本文整理汇总了C#中CvMat类的典型用法代码示例。如果您正苦于以下问题:C# CvMat类的具体用法?C# CvMat怎么用?C# CvMat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CvMat类属于命名空间,在下文中一共展示了CvMat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public static void Read(out CvMat matrix, XmlElement element)
{
int cols = int.Parse(element.GetAttribute("cols"));
int rows = int.Parse(element.GetAttribute("rows"));
MatrixType matType = (MatrixType)Enum.Parse(typeof(MatrixType), element.GetAttribute("type"));
string terms = element.GetAttribute("values");
List<double> values = new List<double>();
string[] words = terms.Split(',');
foreach (string w in words)
values.Add(double.Parse(w.Trim()));
switch (matType)
{
case MatrixType.F32C1:
break;
case MatrixType.F64C1:
break;
default:
throw new Exception("Read unsupported MatrixType " + matType.ToString());
}
matrix = new CvMat(rows, cols, matType);
// Fill the matrix popping values off
for (int x = 0; x < cols; ++x)
{
for (int y = 0; y < rows; ++y)
{
matrix.Set2D(x, y, new CvScalar(values[0]));
values.RemoveAt(0);
}
}
}
示例2: Read
public void Read(XmlElement me)
{
foreach (XmlNode node in me.ChildNodes)
{
if (node is XmlElement)
{
if (node.Name == "rotation")
{
CvMat mat;
OpenCVUtil.Read(out mat, node as XmlElement);
Rotation = mat;
}
else if (node.Name == "translation")
{
CvMat mat;
OpenCVUtil.Read(out mat, node as XmlElement);
Translation = mat;
}
else if (node.Name == "intrinsic")
{
CvMat mat;
OpenCVUtil.Read(out mat, node as XmlElement);
Intrinsic = mat;
}
else if (node.Name == "distortion")
{
CvMat mat;
OpenCVUtil.Read(out mat, node as XmlElement);
Distortion = mat;
}
}
}
}
示例3: FlannColoredModelPoints
public FlannColoredModelPoints(List<Tuple<CvPoint3D64f, CvColor>> modelPoints, IndexParams indexParams, SearchParams searchParams, double colorScale)
{
_modelPoints = modelPoints;
_modelMat = new CvMat(_modelPoints.Count, 6, MatrixType.F32C1);
unsafe
{
float* modelArr = _modelMat.DataSingle;
foreach (var tuple in _modelPoints)
{
*(modelArr++) = (float)tuple.Item1.X;
*(modelArr++) = (float)tuple.Item1.Y;
*(modelArr++) = (float)tuple.Item1.Z;
*(modelArr++) = (float)(tuple.Item2.R * colorScale / 255);
*(modelArr++) = (float)(tuple.Item2.G * colorScale / 255);
*(modelArr++) = (float)(tuple.Item2.B * colorScale / 255);
}
}
_colorScale = colorScale;
_modelDataMat = new Mat(_modelMat);
_indexParam = indexParams;
_searchParam = searchParams;
_indexParam.IsEnabledDispose = false;
_searchParam.IsEnabledDispose = false;
_flannIndex = new Index(_modelDataMat, _indexParam);
}
示例4: CvDTreeTrainData
/// <summary>
/// 学習データを与えて初期化
/// </summary>
/// <param name="trainData"></param>
/// <param name="tflag"></param>
/// <param name="responses"></param>
/// <param name="varIdx"></param>
/// <param name="sampleIdx"></param>
/// <param name="varType"></param>
/// <param name="missingMask"></param>
/// <param name="param"></param>
/// <param name="shared"></param>
/// <param name="addLabels"></param>
/// <returns></returns>
#else
/// <summary>
/// Training constructor
/// </summary>
/// <param name="trainData"></param>
/// <param name="tflag"></param>
/// <param name="responses"></param>
/// <param name="varIdx"></param>
/// <param name="sampleIdx"></param>
/// <param name="varType"></param>
/// <param name="missingMask"></param>
/// <param name="param"></param>
/// <param name="shared"></param>
/// <param name="addLabels"></param>
/// <returns></returns>
#endif
public CvDTreeTrainData(
CvMat trainData,
DTreeDataLayout tflag,
CvMat responses,
CvMat varIdx = null,
CvMat sampleIdx = null,
CvMat varType = null,
CvMat missingMask = null,
CvDTreeParams param = null,
bool shared = false,
bool addLabels = false)
{
if (trainData == null)
throw new ArgumentNullException("trainData");
if (responses == null)
throw new ArgumentNullException("responses");
trainData.ThrowIfDisposed();
responses.ThrowIfDisposed();
if(param == null)
param = new CvDTreeParams();
ptr = NativeMethods.ml_CvDTreeTrainData_new2(
trainData.CvPtr,
(int)tflag,
responses.CvPtr,
Cv2.ToPtr(varIdx),
Cv2.ToPtr(sampleIdx),
Cv2.ToPtr(varType),
Cv2.ToPtr(missingMask),
param.CvPtr,
shared ? 1 : 0,
addLabels ? 1 : 0
);
}
示例5: cariX
public void cariX(IplImage imgSrc, ref int min, ref int max)
{
bool minTemu = false;
data = new CvMat();
CvScalar maxVal = cvlib.cvRealScalar(imgSrc.width * 255);
CvScalar val = cvlib.cvRealScalar(0);
//For each column sum, if sum <width * 255 then we find min
//then proceed to the end of me to find max, if sum <width * 255 then found a new max
for (int i = 0; i < imgSrc.width; i++)
{
cvlib.cvGetCol( imgSrc, data, i); //col
val = cvlib.cvSum( data);
if (val.Val < maxVal.Val)
{
max = i;
if (!minTemu)
{
min = i;
minTemu = true;
}
}
}
}
示例6: CreatePointCountMatrix
private static CvMat CreatePointCountMatrix(int numPoints)
{
int[] pointCountsValue = new int[_numImages];
pointCountsValue[0] = numPoints;
CvMat pointCounts = new CvMat(_numImages, 1, MatrixType.S32C1, pointCountsValue);
return pointCounts;
}
示例7: cariY
public void cariY(IplImage imgSrc, ref int min, ref int max)
{
bool minFound = false;
data = new CvMat();
CvScalar maxVal = cvlib.cvRealScalar(imgSrc.width * 255);
CvScalar val = cvlib.cvRealScalar(0);
//For each row sum, if sum <width * 255 then we find min
//then proceed to the end of me to find max, if sum <width * 255 then found a new max
for (int i = 0; i < imgSrc.height; i++)
{
cvlib.cvGetRow( imgSrc, data, i); //row
val = cvlib.cvSum( data);
if (val.val1 < maxVal.val1)
{
max = i;
if (!minFound)
{
min = i;
minFound = true;
}
}
}
}
示例8: ApplyCalibrationToUnityCamera
private void ApplyCalibrationToUnityCamera(CvMat intrinsic, CvMat rotation, CvMat translation)
{
CvMat rotationInverse = GetRotationMatrixFromRotationVector(rotation).Transpose(); // transpose is same as inverse for rotation matrix
CvMat transFinal = (rotationInverse * -1) * translation.Transpose();
_mainCamera.projectionMatrix = LoadProjectionMatrix((float)intrinsic[0, 0], (float)intrinsic[1, 1], (float)intrinsic[0, 2], (float)intrinsic[1, 2]);
ApplyTranslationAndRotationToCamera(transFinal, RotationConversion.RotationMatrixToEulerZXY(rotationInverse));
}
示例9: GetBytesFromData
public static byte[] GetBytesFromData(CvMat mat)
{
int byteLength = mat.ElemDepth * mat.Cols * mat.Rows * mat.ElemChannels / 8;
byte[] ret = new byte[byteLength];
Marshal.Copy(mat.Data, ret, 0, byteLength);
return ret;
}
示例10: CalcPoint
void CalcPoint(CvMat velx, CvMat vely, IplImage rez)
{
int sX = 0;
int sY = 0;
int coun = 0;
for (int x = 0; x < imWidth; x += 10)
{
for (int y = 0; y < imHeight; y += 10)
{
int dx = (int)Cv.GetReal2D(velx, y, x);
int dy = (int)Cv.GetReal2D(vely, y, x);
if (dx > 15 || dy > 15)
{
Cv.Line(rez, Cv.Point(x, y), Cv.Point(x + dx, y + dy), Cv.RGB(0, 0, 255), 1, Cv.AA, 0);
sX += x;
sY += y;
coun++;
}
if (dx < -15 || dy < -15)
{
Cv.Line(rez, Cv.Point(x, y), Cv.Point(x + dx, y + dy), Cv.RGB(0, 255, 0), 1, Cv.AA, 0);
sX += x;
sY += y;
coun++;
}
}
}
if (coun > 10)
{
moveVec.Set(sX / coun, sY / coun, 0);
}
}
示例11: cariX
public void cariX(IplImage imgSrc, ref int min, ref int max)
{
bool minTemu = false;
data = new CvMat();
CvScalar maxVal = cxtypes.cvRealScalar(imgSrc.width * 255);
CvScalar val = cxtypes.cvRealScalar(0);
//utk setiap kolom sum, jika sum < width*255 maka kita temukan min
//kemudian lanjutkan hingga akhir utk menemukan max, jika sum < width*255 maka ditemukan max baru
for (int i = 0; i < imgSrc.width; i++)
{
cxcore.CvGetCol(ref imgSrc, ref data, i); //col
val = cxcore.CvSum(ref data);
if (val.val1 < maxVal.val1)
{
max = i;
if (!minTemu)
{
min = i;
minTemu = true;
}
}
}
}
示例12: Solve
public Solve()
{
// x + y + z = 6
// 2x - 3y + 4z = 8
// 4x + 4y - 4z = 0
double[] A = new double[]{
1, 1, 1,
2, -3, 4,
4, 4, -4
};
double[] B = new double[]{
6,
8,
0
};
CvMat matA = new CvMat(3, 3, MatrixType.F64C1, A);
CvMat matB = new CvMat(3, 1, MatrixType.F64C1, B);
// X = inv(A) * B
CvMat matAInv = matA.Clone();
matA.Inv(matAInv);
CvMat matX = matAInv * matB;
Console.WriteLine("X = {0}", matX[0].Val0);
Console.WriteLine("Y = {0}", matX[1].Val0);
Console.WriteLine("Z = {0}", matX[2].Val0);
Console.Read();
}
示例13: CvBoost
/// <summary>
/// 学習データを与えて初期化
/// </summary>
/// <param name="trainData"></param>
/// <param name="tflag"></param>
/// <param name="responses"></param>
/// <param name="varIdx"></param>
/// <param name="sampleIdx"></param>
/// <param name="varType"></param>
/// <param name="missingMask"></param>
/// <param name="param"></param>
#else
/// <summary>
/// Training constructor
/// </summary>
/// <param name="trainData"></param>
/// <param name="tflag"></param>
/// <param name="responses"></param>
/// <param name="varIdx"></param>
/// <param name="sampleIdx"></param>
/// <param name="varType"></param>
/// <param name="missingMask"></param>
/// <param name="param"></param>
#endif
public CvBoost(
CvMat trainData,
DTreeDataLayout tflag,
CvMat responses,
CvMat varIdx = null,
CvMat sampleIdx = null,
CvMat varType = null,
CvMat missingMask = null,
CvBoostParams param = null)
{
if (trainData == null)
throw new ArgumentNullException("trainData");
if (responses == null)
throw new ArgumentNullException("responses");
trainData.ThrowIfDisposed();
responses.ThrowIfDisposed();
if (param == null)
param = new CvBoostParams();
ptr = NativeMethods.ml_CvBoost_new_CvMat(
trainData.CvPtr,
(int)tflag,
responses.CvPtr,
Cv2.ToPtr(varIdx),
Cv2.ToPtr(sampleIdx),
Cv2.ToPtr(varType),
Cv2.ToPtr(missingMask),
param.CvPtr
);
}
示例14: MainLoop
public static void MainLoop()
{
PROCESS.SetWindowPos(0, 0, 800, 600);
Thread.Sleep(200);
foreach (var image in ImageList)
{
CvMat screen = Utils.TakeScreenshot().ToMat().ToCvMat();
Screenshot = new CvMat(screen.Rows, screen.Cols, MatrixType.U8C1);
screen.CvtColor(Screenshot, ColorConversion.BgraToGray);
Result =
Cv.CreateImage(Cv.Size(Screenshot.Width - image.Width + 1, Screenshot.Height - image.Height + 1),
BitDepth.F32, 1);
Cv.MatchTemplate(Screenshot, image, Result, MatchTemplateMethod.CCoeffNormed);
/*Screenshot.SaveImage("data/screenshot.png");
image.SaveImage("data/image.png");*/
Cv.Normalize(Result, Result, 0, 1, NormType.MinMax);
Cv.MinMaxLoc(Result, out MinAcc, out MaxAcc, out MinPos, out MaxPos, null);
Console.WriteLine(MaxAcc);
if (MaxAcc >= 0.75)
{
Position = new Point(MaxPos.X, MaxPos.Y);
Utils.MoveMouse(Position);
Thread.Sleep(15);
Utils.LeftClick();
Thread.Sleep(100);
MaxAcc = 0;
}
Result.Dispose();
}
}
示例15: RotationMatrixToEulerZXY
static public Rotation RotationMatrixToEulerZXY(CvMat R)
{
var i = 2;
var j = 0; // EULER_NEXT[2]
var k = 1; // EULER_NEXT[3]
var cos_beta = Math.Sqrt(Math.Pow(R[i, i], 2) + Math.Pow(R[j, i], 2));
double alpha, beta, gamma;
if (cos_beta > EULER_EPSILON)
{
alpha = Math.Atan2(R[k, j], R[k, k]);
beta = Math.Atan2(-R[k, i], cos_beta);
gamma = Math.Atan2(R[j, i], R[i, i]);
}
else
{
alpha = Math.Atan2(-R[j, k], R[j, j]);
beta = Math.Atan2(-R[k, i], cos_beta);
gamma = 0.0;
}
alpha = wrap_angles(alpha, 0.0, 2.0 * Math.PI); // Z
beta = wrap_angles(beta, 0.0, 2.0 * Math.PI); // X
gamma = wrap_angles(gamma, 0.0, 2.0 * Math.PI); // Y
// errr... 180 - Z result seems right. Why?
return new Rotation(RadianToDegree(beta), RadianToDegree(gamma), 180.0 - RadianToDegree(alpha));
}