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


C# Mat.submat方法代码示例

本文整理汇总了C#中Mat.submat方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.submat方法的具体用法?C# Mat.submat怎么用?C# Mat.submat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mat的用法示例。


在下文中一共展示了Mat.submat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

				// Use this for initialization
				void Start ()
				{

						List<Mat> images = new List<Mat> ();
						List<int> labelsList = new List<int> ();
						MatOfInt labels = new MatOfInt ();
						images.Add (Highgui.imread (Utils.getFilePath ("facerec/facerec_0.bmp"), 0));
						images.Add (Highgui.imread (Utils.getFilePath ("facerec/facerec_1.bmp"), 0));

						labelsList.Add (0);
						labelsList.Add (1);
						labels.fromList (labelsList);

						Mat testSampleMat = Highgui.imread (Utils.getFilePath ("facerec/facerec_sample.bmp"), 0);

						int testSampleLabel = 0;


//						foreach (Mat item in images) {
//								Debug.Log ("images.ToString " + item.ToString ());
//						}
//						foreach (int item in labelsList) {
//								Debug.Log ("labels.ToString " + item.ToString ());
//						}

						int[] predictedLabel = new int[1];
						double[] predictedConfidence = new double[1];

			
						FaceRecognizer faceRecognizer = FaceRecognizer.createEigenFaceRecognizer ();

						faceRecognizer.train (images, labels);

						faceRecognizer.predict (testSampleMat, predictedLabel, predictedConfidence);


						Debug.Log ("Predicted class: " + predictedLabel [0] + " / " + "Actual class: " + testSampleLabel);
						Debug.Log ("Confidence: " + predictedConfidence [0]);


						Mat predictedMat = images [predictedLabel [0]];

						Mat baseMat = new Mat (testSampleMat.rows (), predictedMat.cols () + testSampleMat.cols (), CvType.CV_8UC1);
						predictedMat.copyTo (baseMat.submat (new OpenCVForUnity.Rect (0, 0, predictedMat.cols (), predictedMat.rows ())));
						testSampleMat.copyTo (baseMat.submat (new OpenCVForUnity.Rect (predictedMat.cols (), 0, testSampleMat.cols (), testSampleMat.rows ())));

						Core.putText (baseMat, "Predicted", new Point (10, baseMat.rows () - 5), Core.FONT_HERSHEY_SIMPLEX, 0.4, new Scalar (255), 1, Core.LINE_AA, false);
						Core.putText (baseMat, "TestSample", new Point (predictedMat.cols () + 10, baseMat.rows () - 5), Core.FONT_HERSHEY_SIMPLEX, 0.4, new Scalar (255), 1, Core.LINE_AA, false);

			
						Texture2D texture = new Texture2D (baseMat.cols (), baseMat.rows (), TextureFormat.RGBA32, false);

						Utils.matToTexture2D (baseMat, texture);

						gameObject.GetComponent<Renderer> ().material.mainTexture = texture;

				}
开发者ID:lsewata,项目名称:OpenCVForUnity,代码行数:58,代码来源:FaceRecognizerSample.cs

示例2: onTouch

        /// <summary>
        /// Ons the touch.
        /// </summary>
        /// <param name="touchPoint">Touch point.</param>
        public void onTouch(Mat rgbaMat, Point touchPoint)
        {
            int cols = rgbaMat.cols ();
                        int rows = rgbaMat.rows ();

                        int x = (int)touchPoint.x;
                        int y = (int)touchPoint.y;

            //						Debug.Log ("Touch image coordinates: (" + x + ", " + y + ")");

                        if ((x < 0) || (y < 0) || (x > cols) || (y > rows))
                                return;

                        OpenCVForUnity.Rect touchedRect = new OpenCVForUnity.Rect ();

                        touchedRect.x = (x > 5) ? x - 5 : 0;
                        touchedRect.y = (y > 5) ? y - 5 : 0;

                        touchedRect.width = (x + 5 < cols) ? x + 5 - touchedRect.x : cols - touchedRect.x;
                        touchedRect.height = (y + 5 < rows) ? y + 5 - touchedRect.y : rows - touchedRect.y;

                        Mat touchedRegionRgba = rgbaMat.submat (touchedRect);

                        Mat touchedRegionHsv = new Mat ();
                        Imgproc.cvtColor (touchedRegionRgba, touchedRegionHsv, Imgproc.COLOR_RGB2HSV_FULL);

                        // Calculate average color of touched region
                        blobColorHsv = Core.sumElems (touchedRegionHsv);
                        int pointCount = touchedRect.width * touchedRect.height;
                        for (int i = 0; i < blobColorHsv.val.Length; i++)
                                blobColorHsv.val [i] /= pointCount;

                        //blobColorRgba = converScalarHsv2Rgba (blobColorHsv);

            //						Debug.Log ("Touched rgba color: (" + mBlobColorRgba.val [0] + ", " + mBlobColorRgba.val [1] +
            //								", " + mBlobColorRgba.val [2] + ", " + mBlobColorRgba.val [3] + ")");

                        detector.setHsvColor (blobColorHsv);

                        Imgproc.resize (detector.getSpectrum (), spectrumMat, SPECTRUM_SIZE);

                        isColorSelected = true;

                        touchedRegionRgba.release ();
                        touchedRegionHsv.release ();
        }
开发者ID:ygx2011,项目名称:OpenCVForUnity,代码行数:50,代码来源:HandPoseEstimationSample.cs


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