• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CvMat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CvMat的典型用法代码示例。如果您正苦于以下问题:C# CvMat类的具体用法?C# CvMat怎么用?C# CvMat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CvMat类属于命名空间,在下文中一共展示了CvMat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: CvSVM

        /// <summary>
        /// 初期化
        /// </summary>
        /// <param name="trainData"></param>
		/// <param name="responses"></param>
        /// <param name="varIdx"></param>
        /// <param name="sampleIdx"></param>
		/// <param name="param"></param>
#else
		/// <summary>
        /// Training constructor
        /// </summary>
		/// <param name="trainData"></param>
		/// <param name="responses"></param>
		/// <param name="varIdx"></param>
		/// <param name="sampleIdx"></param>
		/// <param name="param"></param>
#endif
		public CvSVM(
            CvMat trainData, 
            CvMat responses, 
            CvMat varIdx = null, 
            CvMat sampleIdx = null, 
            CvSVMParams param = null)
	    {
            if (trainData == null)
                throw new ArgumentNullException("trainData");
            if (responses == null)
                throw new ArgumentNullException("responses");

			if(param == null)
				param = new CvSVMParams();
            trainData.ThrowIfDisposed();
            responses.ThrowIfDisposed();

            ptr = NativeMethods.ml_CvSVM_new2_CvMat(
				trainData.CvPtr, 
				responses.CvPtr, 
				Cv2.ToPtr(varIdx), 
				Cv2.ToPtr(sampleIdx), 
				param.NativeStruct
			);
        }
开发者ID:MJunak,项目名称:opencvsharp,代码行数:43,代码来源:CvSVM.cs


示例17: SerializableCvMat

 public SerializableCvMat(CvMat mat)
 {
     this.Cols = mat.Cols;
     this.Rows = mat.Rows;
     this.ElemType = mat.ElemType;
     this.Array = mat.ToArray();
 }
开发者ID:guozanhua,项目名称:KinectMotionCapture,代码行数:7,代码来源:SerializableCvMat.cs


示例18: Filter2D

        public Filter2D()
        {
            // cvFilter2D
            // ユーザが定義したカーネルによるフィルタリング

            // (1)画像の読み込み
            using (IplImage srcImg = new IplImage(Const.ImageFruits, LoadMode.AnyDepth | LoadMode.AnyColor))
            using (IplImage dstImg = new IplImage(srcImg.Size, srcImg.Depth, srcImg.NChannels))
            {
                // (2)カーネルの正規化と,フィルタ処理
                float[] data = {    2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
                                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                };
                CvMat kernel = new CvMat(1, 21, MatrixType.F32C1, data);

                Cv.Normalize(kernel, kernel, 1.0, 0, NormType.L1);
                Cv.Filter2D(srcImg, dstImg, kernel, new CvPoint(0, 0));

                // (3)結果を表示する
                using (CvWindow window = new CvWindow("Filter2D", dstImg))
                {
                    Cv.WaitKey(0);
                }
            }

        }
开发者ID:healtech,项目名称:opencvsharp,代码行数:26,代码来源:Filter2D.cs


示例19: applyLinearFilter

        private static void applyLinearFilter()
        {
            using (var src = new IplImage(@"..\..\Images\Penguin.Png", LoadMode.AnyDepth | LoadMode.AnyColor))
            using (var dst = new IplImage(src.Size, src.Depth, src.NChannels))
            {
                float[] data = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
                var kernel = new CvMat(rows: 1, cols: 21, type: MatrixType.F32C1, elements: data);

                Cv.Normalize(src: kernel, dst: kernel, a: 1.0, b: 0, normType: NormType.L1);

                double sum = 0;
                foreach (var item in data)
                {
                    sum += Math.Abs(item);
                }
                Console.WriteLine(sum); // => .999999970197678

                Cv.Filter2D(src, dst, kernel, anchor: new CvPoint(0, 0));

                using (new CvWindow("src", image: src))
                using (new CvWindow("dst", image: dst))
                {
                    Cv.WaitKey(0);
                }
            }
        }
开发者ID:kauser-cse-buet,项目名称:OpenCVSharp-Samples,代码行数:26,代码来源:Program.cs


示例20: CalcPoint

	void CalcPoint(CvMat velx, CvMat vely, IplImage rez)
	{
		int sX = 0;
		int sY = 0;
		int coun = 0;
		for (int x = 0; x < cols; x += 10) {
			for (int y = 0; y < rows; y += 10) {
				int dx = (int)Cv.GetReal2D (velx, y, x);
				int dy = (int)Cv.GetReal2D (vely, y, x);
				if(Mathf.Abs(dx)>8 && Mathf.Abs(dy)>8 && Mathf.Abs(dx)<75 && Mathf.Abs(dy)<75)
				{
					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(y == 0 && x == cols/8*3 || y == 0 && x == cols/8*5 )
                {
                    Debug.Log("wewe");
                    Cv.Line(rez, Cv.Point(x, 0), Cv.Point(x, rows), Cv.RGB(255, 0, 0), 3, Cv.AA, 0);
                }

                if (x == 0 && y == rows / 3 || x == 0 && y == rows / 3 * 2)
                {
                    Cv.Line(rez, Cv.Point(0, y), Cv.Point(cols, y), Cv.RGB(255, 0, 0), 3, Cv.AA, 0);
                }
			}
		}
		if (coun >15) {
            Cv.Circle(rez, Cv.Point(sX / coun, sY / coun),30, Cv.RGB(255, 255, 0),5);
			moveVec.Set (sX / coun, sY / coun, 0);
		}
	}
开发者ID:MaksimSychugov,项目名称:SpaceshipGesture,代码行数:35,代码来源:UnityCvTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CvPoint类代码示例发布时间:2022-05-24
下一篇:
C# CvEnum类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap