当前位置: 首页>>代码示例>>C#>>正文


C# CvMat类代码示例

本文整理汇总了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);
                }
            }
        }
开发者ID:CodeMason,项目名称:ImageBasedMocap,代码行数:32,代码来源:OpenCVUtil.cs

示例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;
                    }
                }
            }
        }
开发者ID:CodeMason,项目名称:ImageBasedMocap,代码行数:34,代码来源:CalibrationData.cs

示例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);
        }
开发者ID:guozanhua,项目名称:KinectMotionCapture,代码行数:26,代码来源:ColoredIterativePointMatching.cs

示例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
			);
		}
开发者ID:kaorun55,项目名称:opencvsharp,代码行数:65,代码来源:CvDTreeTrainData.cs

示例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;
                    }
                }
            }
        }
开发者ID:rahulgarg1994,项目名称:empower_talk2,代码行数:26,代码来源:preprocessing.cs

示例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;
 }
开发者ID:guozanhua,项目名称:UnityProjectionMapping,代码行数:7,代码来源:Calibration.cs

示例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;
                    }
                }
            }
        }
开发者ID:rahulgarg1994,项目名称:empower_talk2,代码行数:26,代码来源:preprocessing.cs

示例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));
 }
开发者ID:guozanhua,项目名称:UnityProjectionMapping,代码行数:7,代码来源:Calibration.cs

示例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;
 }
开发者ID:guozanhua,项目名称:KinectMotionCapture,代码行数:7,代码来源:SerializableCvMat.cs

示例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);
     }
 }
开发者ID:MaksimSychugov,项目名称:SpaceshipGesture,代码行数:32,代码来源:WebCamera.cs

示例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;
                    }
                }
            }
        }
开发者ID:Juniar-Rakhman,项目名称:OpenCV_ASL_Recognition,代码行数:26,代码来源:preprocessing.cs

示例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();
        }
开发者ID:qxp1011,项目名称:opencvsharp,代码行数:31,代码来源:Solve.cs

示例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
			);
		}
开发者ID:kaorun55,项目名称:opencvsharp,代码行数:55,代码来源:CvBoost.cs

示例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();
            }
        }
开发者ID:rpgfreak128,项目名称:Experimental,代码行数:31,代码来源:Program.cs

示例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));
        }
开发者ID:guozanhua,项目名称:UnityProjectionMapping,代码行数:29,代码来源:RotationConversion.cs


注:本文中的CvMat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。