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


C# Mat.cols方法代码示例

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


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

示例1: Start

        // Use this for initialization
        void Start()
        {
            //Read the left and right images
            Texture2D texLeft = Resources.Load ("tsukuba_l") as Texture2D;
            Texture2D texRight = Resources.Load ("tsukuba_r") as Texture2D;
            Mat imgLeft = new Mat (texLeft.height, texLeft.width, CvType.CV_8UC1);
            Mat imgRight = new Mat (texRight.height, texRight.width, CvType.CV_8UC1);
            Utils.texture2DToMat (texLeft, imgLeft);
            Utils.texture2DToMat (texRight, imgRight);
            //or
            //Mat imgLeft = Imgcodecs.imread (Utils.getFilePath ("tsukuba_l.png"), Imgcodecs.IMREAD_GRAYSCALE);
            //Mat imgRight = Imgcodecs.imread (Utils.getFilePath ("tsukuba_r.png"), Imgcodecs.IMREAD_GRAYSCALE);

            Mat imgDisparity16S = new Mat (imgLeft.rows (), imgLeft.cols (), CvType.CV_16S);
            Mat imgDisparity8U = new Mat (imgLeft.rows (), imgLeft.cols (), CvType.CV_8UC1);

            if (imgLeft.empty () || imgRight.empty ()) {
                Debug.Log ("Error reading images ");
            }

            StereoBM sbm = StereoBM.create (16, 15);

            sbm.compute (imgLeft, imgRight, imgDisparity16S);

            //normalize to CvType.CV_8U
            Core.normalize (imgDisparity16S, imgDisparity8U, 0, 255, Core.NORM_MINMAX, CvType.CV_8U);

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

            Utils.matToTexture2D (imgDisparity8U, texture);

            gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
        }
开发者ID:EnoxSoftware,项目名称:OpenCVForUnity,代码行数:34,代码来源:StereoBMSample.cs

示例2: Start

        // Use this for initialization
        void Start()
        {
            Texture2D inputTexture = Resources.Load ("lena") as Texture2D;

                        Mat inputMat = new Mat (inputTexture.height, inputTexture.width, CvType.CV_8UC4);

                        Utils.texture2DToMat (inputTexture, inputMat);
                        Debug.Log ("inputMat dst ToString " + inputMat.ToString ());

                        Mat src_mat = new Mat (4, 1, CvType.CV_32FC2);
                        Mat dst_mat = new Mat (4, 1, CvType.CV_32FC2);

                        src_mat.put (0, 0, 0.0, 0.0, inputMat.rows (), 0.0, 0.0, inputMat.cols (), inputMat.rows (), inputMat.cols ());
                        dst_mat.put (0, 0, 0.0, 0.0, inputMat.rows (), 200.0, 0.0, inputMat.cols (), inputMat.rows (), inputMat.cols () - 200.0);
                        Mat perspectiveTransform = Imgproc.getPerspectiveTransform (src_mat, dst_mat);

                        Mat outputMat = inputMat.clone ();

                        Imgproc.warpPerspective (inputMat, outputMat, perspectiveTransform, new Size (inputMat.rows (), inputMat.cols ()));

                        Texture2D outputTexture = new Texture2D (outputMat.cols (), outputMat.rows (), TextureFormat.RGBA32, false);

                        Utils.matToTexture2D (outputMat, outputTexture);

                        gameObject.GetComponent<Renderer> ().material.mainTexture = outputTexture;
        }
开发者ID:ygx2011,项目名称:OpenCVForUnity,代码行数:27,代码来源:WrapPerspectiveSample.cs

示例3: Start

				// Use this for initialization
				void Start ()
				{

						//initialize FaceTracker
						FaceTracker faceTracker = new FaceTracker (Utils.getFilePath ("tracker_model.json"));
						//initialize FaceTrackerParams
						FaceTrackerParams faceTrackerParams = new FaceTrackerParams ();


						gameObject.transform.localScale = new Vector3 (imgTexture.width, imgTexture.height, 1);
						Camera.main.orthographicSize = imgTexture.height / 2;
		
						Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);
		
						Utils.texture2DToMat (imgTexture, imgMat);
						Debug.Log ("imgMat dst ToString " + imgMat.ToString ());


						CascadeClassifier cascade = new CascadeClassifier (Utils.getFilePath ("haarcascade_frontalface_alt.xml"));
						if (cascade.empty ()) {
								Debug.LogError ("cascade file is not loaded.Please copy from “FaceTrackerSample/StreamingAssets/” to “Assets/StreamingAssets/” folder. ");
						}

						//convert image to greyscale
						Mat gray = new Mat ();
						Imgproc.cvtColor (imgMat, gray, Imgproc.COLOR_RGBA2GRAY);

		
						MatOfRect faces = new MatOfRect ();
		
						Imgproc.equalizeHist (gray, gray);
		
						cascade.detectMultiScale (gray, faces, 1.1f, 2, 0
//								                           | Objdetect.CASCADE_FIND_BIGGEST_OBJECT
								| Objdetect.CASCADE_SCALE_IMAGE, new OpenCVForUnity.Size (gray.cols () * 0.05, gray.cols () * 0.05), new Size ());
		
						Debug.Log ("faces " + faces.dump ());
		
						if (faces.rows () > 0) {
								//add initial face points from MatOfRect
								faceTracker.addPoints (faces);
						}


						//track face points.if face points <= 0, always return false.
						if (faceTracker.track (imgMat, faceTrackerParams))
								faceTracker.draw (imgMat, new Scalar (255, 0, 0, 255), new Scalar (0, 255, 0, 255));


		
						Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
		
		
						Utils.matToTexture2D (imgMat, texture);
		
						gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
				}
开发者ID:Thecontrarian,项目名称:unity-blink-detection,代码行数:58,代码来源:Texture2DFaceTrackerSample.cs

示例4: rotate

		/// <summary>
		/// Rotate the specified inMat.
		/// </summary>
		/// <param name="inMat">In mat.</param>
		public static Mat rotate (Mat inMat)
		{
				byte[] b = new byte[1];

				Mat outMat = new Mat ();
				inMat.copyTo (outMat);
				for (int i=0; i<inMat.rows(); i++) {
						for (int j=0; j<inMat.cols(); j++) {
								inMat.get (inMat.cols () - j - 1, i, b);
								outMat.put (i, j, b);

						}
				}
				return outMat;
		}
开发者ID:wlstks7,项目名称:MarkerBasedARSample,代码行数:19,代码来源:Marker.cs

示例5: Start

        // Use this for initialization
        void Start()
        {
            Texture2D imgTexture = Resources.Load ("chessboard") as Texture2D;

                        Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC3);

                        Utils.texture2DToMat (imgTexture, imgMat);
                        Debug.Log ("imgMat dst ToString " + imgMat.ToString ());

                        Mat grayMat = new Mat ();
                        Imgproc.cvtColor (imgMat, grayMat, Imgproc.COLOR_RGB2GRAY);

                        Imgproc.Canny (grayMat, grayMat, 50, 200);

                        Mat lines = new Mat ();

                        Imgproc.HoughLinesP (grayMat, lines, 1, Mathf.PI / 180, 50, 50, 10);

            //						Debug.Log ("lines toStirng " + lines.ToString ());
            //						Debug.Log ("lines dump" + lines.dump ());

                        int[] linesArray = new int[lines.cols () * lines.rows () * lines.channels ()];
                        lines.get (0, 0, linesArray);

                        for (int i = 0; i < linesArray.Length; i=i+4) {
                                Core.line (imgMat, new Point (linesArray [i + 0], linesArray [i + 1]), new Point (linesArray [i + 2], linesArray [i + 3]), new Scalar (255, 0, 0), 2);
                        }

                        Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
                        Utils.matToTexture2D (imgMat, texture);

                        gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
        }
开发者ID:prlosana,项目名称:OpenCVForUnity,代码行数:34,代码来源:HoughLinesPSample.cs

示例6: Start

        // Use this for initialization
        void Start()
        {
            Texture2D imgTexture = Resources.Load ("lena") as Texture2D;

                        Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);

                        Utils.texture2DToMat (imgTexture, imgMat);
                        Debug.Log ("imgMat dst ToString " + imgMat.ToString ());

                        //CascadeClassifier cascade = new CascadeClassifier (Utils.getFilePath ("lbpcascade_frontalface.xml"));
                        CascadeClassifier cascade = new CascadeClassifier (Utils.getFilePath ("haarcascade_frontalface_alt.xml"));

                        Mat grayMat = new Mat ();
                        Imgproc.cvtColor (imgMat, grayMat, Imgproc.COLOR_RGBA2GRAY);
                        Imgproc.equalizeHist (grayMat, grayMat);

                        MatOfRect faces = new MatOfRect ();

                        if (cascade != null)
                                cascade.detectMultiScale (grayMat, faces, 1.1, 2, 2,
                                           new Size (20, 20), new Size ());

                        OpenCVForUnity.Rect[] rects = faces.toArray ();
                        for (int i = 0; i < rects.Length; i++) {
                                Debug.Log ("detect faces " + rects [i]);

                                Core.rectangle (imgMat, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (255, 0, 0, 255), 2);
                        }

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

                        Utils.matToTexture2D (imgMat, texture);

                        gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
        }
开发者ID:chaffman,项目名称:OpenCVForUnity,代码行数:36,代码来源:DetectFaceSample.cs

示例7: Start

        // Use this for initialization
        void Start()
        {
            Texture2D imgTexture = Resources.Load ("detect_blob") as Texture2D;

                        Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC1);

                        Utils.texture2DToMat (imgTexture, imgMat);
                        Debug.Log ("imgMat dst ToString " + imgMat.ToString ());

                        Mat outImgMat = new Mat ();

                        FeatureDetector blobDetector = FeatureDetector.create (FeatureDetector.SIMPLEBLOB);

                        blobDetector.read (Utils.getFilePath ("blobparams.yml"));

                        MatOfKeyPoint keypoints = new MatOfKeyPoint ();
                        blobDetector.detect (imgMat, keypoints);
                        Features2d.drawKeypoints (imgMat, keypoints, outImgMat);

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

                        Utils.matToTexture2D (outImgMat, texture);

                        gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
        }
开发者ID:ygx2011,项目名称:OpenCVForUnity,代码行数:26,代码来源:SimpleBlobSample.cs

示例8: Start

				// Use this for initialization
				void Start ()
				{


						Texture2D imgTexture = Resources.Load ("lena") as Texture2D;
			
						Mat img1Mat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC3);
						Utils.texture2DToMat (imgTexture, img1Mat);
						Debug.Log ("img1Mat dst ToString " + img1Mat.ToString ());

						Mat img2Mat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC3);
						Utils.texture2DToMat (imgTexture, img2Mat);
						Debug.Log ("img2Mat dst ToString " + img2Mat.ToString ());



						float angle = UnityEngine.Random.Range (0, 360), scale = 1.0f;

						Point center = new Point (img2Mat.cols () * 0.5f, img2Mat.rows () * 0.5f);

						Mat affine_matrix = Imgproc.getRotationMatrix2D (center, angle, scale);

						Imgproc.warpAffine (img1Mat, img2Mat, affine_matrix, img2Mat.size ());


						FeatureDetector detector = FeatureDetector.create (FeatureDetector.ORB);
						DescriptorExtractor extractor = DescriptorExtractor.create (DescriptorExtractor.ORB);

						MatOfKeyPoint keypoints1 = new MatOfKeyPoint ();
						Mat descriptors1 = new Mat ();

						detector.detect (img1Mat, keypoints1);
						extractor.compute (img1Mat, keypoints1, descriptors1);

						MatOfKeyPoint keypoints2 = new MatOfKeyPoint ();
						Mat descriptors2 = new Mat ();
		
						detector.detect (img2Mat, keypoints2);
						extractor.compute (img2Mat, keypoints2, descriptors2);


						DescriptorMatcher matcher = DescriptorMatcher.create (DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
						MatOfDMatch matches = new MatOfDMatch ();

						matcher.match (descriptors1, descriptors2, matches);


						Mat resultImg = new Mat ();

						Features2d.drawMatches (img1Mat, keypoints1, img2Mat, keypoints2, matches, resultImg);



						Texture2D texture = new Texture2D (resultImg.cols (), resultImg.rows (), TextureFormat.RGBA32, false);
		
						Utils.matToTexture2D (resultImg, texture);

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

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

示例9: 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

示例10: Start

				// Use this for initialization
				void Start ()
				{
						Texture2D imgTexture = Resources.Load ("chessboard") as Texture2D;
			
						Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC3);
			
						Utils.texture2DToMat (imgTexture, imgMat);
						Debug.Log ("imgMat dst ToString " + imgMat.ToString ());
						


						Core.line (imgMat, new Point (50, 50), new Point (400, 105), new Scalar (0, 0, 200), 3);  

						Core.rectangle (imgMat, new Point (150, 200), new Point (300, 300), new Scalar (0, 200, 0), 5);

						Core.circle (imgMat, new Point (500, 300), 80, new Scalar (200, 0, 0), 1);

						Core.arrowedLine (imgMat, new Point (100, 500), new Point (550, 350), new Scalar (255, 255, 0), 4, Core.LINE_8, 0, 0.1);


						double angle = 100;
						Core.ellipse (imgMat, new Point (200, 400), new Size (80, 150), angle, angle - 200, angle + 100, new Scalar (255, 255, 255), -1);


						int[] face = {Core.FONT_HERSHEY_SIMPLEX, Core.FONT_HERSHEY_PLAIN, Core.FONT_HERSHEY_DUPLEX, Core.FONT_HERSHEY_COMPLEX, 
			Core.FONT_HERSHEY_TRIPLEX, Core.FONT_HERSHEY_COMPLEX_SMALL, Core.FONT_HERSHEY_SCRIPT_SIMPLEX, 
			Core.FONT_HERSHEY_SCRIPT_COMPLEX, Core.FONT_ITALIC};
		

						Core.putText (imgMat, "OpenCV", new Point (50, 50), face [0], 1.2, new Scalar (0, 0, 200), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (50, 100), face [1], 1.2, new Scalar (0, 200, 0), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (50, 150), face [2], 1.2, new Scalar (200, 0, 0), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (50, 200), face [3], 1.2, new Scalar (0, 100, 100), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (50, 250), face [4], 1.2, new Scalar (100, 100, 0), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (50, 300), face [5], 1.2, new Scalar (100, 0, 100), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (50, 350), face [6], 1.2, new Scalar (100, 100, 100), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (50, 400), face [7], 1.2, new Scalar (100, 100, 200), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (300, 50), face [0] | face [8], 1.2, new Scalar (100, 200, 100), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (300, 100), face [1] | face [8], 1.2, new Scalar (200, 100, 100), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (300, 150), face [2] | face [8], 1.2, new Scalar (200, 200, 100), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (300, 200), face [3] | face [8], 1.2, new Scalar (200, 100, 200), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (300, 250), face [4] | face [8], 1.2, new Scalar (100, 200, 200), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (300, 300), face [5] | face [8], 1.2, new Scalar (100, 200, 255), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (300, 350), face [6] | face [8], 1.2, new Scalar (100, 255, 200), 2, Core.LINE_AA, false);
						Core.putText (imgMat, "OpenCV", new Point (300, 400), face [7] | face [8], 1.2, new Scalar (255, 200, 100), 2, Core.LINE_AA, false);


		
		
						Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
						Utils.matToTexture2D (imgMat, texture);
		
						gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
		
		
				}
开发者ID:lsewata,项目名称:OpenCVForUnity,代码行数:57,代码来源:DrawingSample.cs

示例11: Start

				// Use this for initialization
				void Start ()
				{
	
						Mat imgMat = new Mat (500, 500, CvType.CV_8UC3, new Scalar (0, 0, 0));
						Debug.Log ("imgMat dst ToString " + imgMat.ToString ());


						int rand_num = 50;
						MatOfPoint pointsMat = new MatOfPoint ();
						pointsMat.alloc (rand_num);

						Core.randu (pointsMat, 100, 400);

						Point[] points = pointsMat.toArray ();
						for (int i=0; i<rand_num; ++i) {
						
								Core.circle (imgMat, points [i], 2, new Scalar (255, 255, 255), -1);
						}

	
						MatOfInt hullInt = new MatOfInt ();
						Imgproc.convexHull (pointsMat, hullInt);


						List<Point> pointMatList = pointsMat.toList ();
						List<int> hullIntList = hullInt.toList ();
						List<Point> hullPointList = new List<Point> ();

						for (int j=0; j < hullInt.toList().Count; j++) {
								hullPointList.Add (pointMatList [hullIntList [j]]);
						}

						MatOfPoint hullPointMat = new MatOfPoint ();
		
						hullPointMat.fromList (hullPointList);

						List<MatOfPoint> hullPoints = new List<MatOfPoint> ();

						hullPoints.Add (hullPointMat);
		
		
		
						Imgproc.drawContours (imgMat, hullPoints, -1, new Scalar (0, 255, 0), 2);


						Imgproc.cvtColor (imgMat, imgMat, Imgproc.COLOR_BGR2RGB);

						Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
						Utils.matToTexture2D (imgMat, texture);
		
						gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
				}
开发者ID:lsewata,项目名称:OpenCVForUnity,代码行数:53,代码来源:ConvexHullSample.cs

示例12: Start

        // Use this for initialization
        void Start()
        {
            Texture2D imgTexture = Resources.Load ("lena") as Texture2D;

                        Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);

                        Utils.texture2DToMat (imgTexture, imgMat);
                        Debug.Log ("imgMat dst ToString " + imgMat.ToString ());

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

                        Utils.matToTexture2D (imgMat, texture);

                        gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
        }
开发者ID:prlosana,项目名称:OpenCVForUnity,代码行数:16,代码来源:Texture2DToMatSample.cs

示例13: Start

        // Use this for initialization
        void Start()
        {
            Texture2D imgTexture = Resources.Load ("lena") as Texture2D;
                        Texture2D tempTexture = Resources.Load ("template") as Texture2D;
                        Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);
                        Mat tempMat = new Mat (tempTexture.height, tempTexture.width, CvType.CV_8UC4);
                        Utils.texture2DToMat (imgTexture, imgMat);
                        Utils.texture2DToMat (tempTexture, tempMat);

                        //Create the result mat
                        int result_cols = imgMat.cols () - tempMat.cols () + 1;
                        int result_rows = imgMat.rows () - tempMat.rows () + 1;
                        Mat result = new Mat (result_rows, result_cols, CvType.CV_32FC1);

                        int match_method = Imgproc.TM_CCOEFF_NORMED;

                        Imgproc.matchTemplate (imgMat, tempMat, result, match_method);

                        Imgproc.threshold (result, result, 0.8, 1.0, Imgproc.THRESH_TOZERO);//threshold = 0.8

                        for (int i=0; i<result.rows(); i++) {
                                for (int j=0; j<result.cols(); j++) {
                                        if (result.get (i, j) [0] > 0) {

                                                Imgproc.rectangle (imgMat, new Point (j, i), new Point (j + tempMat.cols (), i + tempMat.rows ()), new Scalar (255, 0, 0, 255), 2);
                                                Debug.Log ("value" + result.get (i, j) [0]);
                                        }
                                }
                        }

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

                        Utils.matToTexture2D (imgMat, texture);

                        gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
        }
开发者ID:ygx2011,项目名称:OpenCVForUnity,代码行数:37,代码来源:MatchTemplateSample.cs

示例14: Start

        // Use this for initialization
        void Start()
        {
            Texture2D imgTexture = Resources.Load ("chessboard") as Texture2D;

                        Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC1);

                        Utils.texture2DToMat (imgTexture, imgMat);
                        Debug.Log ("imgMat dst ToString " + imgMat.ToString ());

                        Imgproc.threshold (imgMat, imgMat, 0, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU);

                        Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
                        Utils.matToTexture2D (imgMat, texture);

                        gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
        }
开发者ID:prlosana,项目名称:OpenCVForUnity,代码行数:17,代码来源:ThresholdSample.cs

示例15: Start

        // Use this for initialization
        void Start()
        {
            //srcMat
            Texture2D srcTexture = Resources.Load ("matchshapes") as Texture2D;
            Mat srcMat = new Mat (srcTexture.height, srcTexture.width, CvType.CV_8UC1);
            Utils.texture2DToMat (srcTexture, srcMat);
            Debug.Log ("srcMat.ToString() " + srcMat.ToString ());
            Imgproc.threshold (srcMat, srcMat, 127, 255, Imgproc.THRESH_BINARY);

            //dstMat
            Texture2D dstTexture = Resources.Load ("matchshapes") as Texture2D;
            Mat dstMat = new Mat (dstTexture.height, dstTexture.width, CvType.CV_8UC3);
            Utils.texture2DToMat (dstTexture, dstMat);
            Debug.Log ("dstMat.ToString() " + dstMat.ToString ());

            List<MatOfPoint> srcContours = new List<MatOfPoint> ();
            Mat srcHierarchy = new Mat ();

            /// Find srcContours
            Imgproc.findContours (srcMat, srcContours, srcHierarchy, Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_NONE);

            Debug.Log ("srcContours.Count " + srcContours.Count);

            for (int i=0; i<srcContours.Count; i++) {
                Imgproc.drawContours (dstMat, srcContours, i, new Scalar (255, 0, 0), 2, 8, srcHierarchy, 0, new Point ());
            }

            for (int i=0; i<srcContours.Count; i++) {
                double returnVal = Imgproc.matchShapes (srcContours [1], srcContours [i], Imgproc.CV_CONTOURS_MATCH_I1, 0);
                Debug.Log ("returnVal " + i + " " + returnVal);

                Point point = new Point ();
                float[] radius = new float[1];
                Imgproc.minEnclosingCircle (new MatOfPoint2f (srcContours [i].toArray ()), point, radius);
                Debug.Log ("point.ToString() " + point.ToString ());
                Debug.Log ("radius.ToString() " + radius [0]);

                Imgproc.circle (dstMat, point, 5, new Scalar (0, 0, 255), -1);
                Imgproc.putText (dstMat, " " + returnVal, point, Core.FONT_HERSHEY_SIMPLEX, 0.4, new Scalar (0, 255, 0), 1, Imgproc.LINE_AA, false);
            }

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

            Utils.matToTexture2D (dstMat, texture);

            gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
        }
开发者ID:EnoxSoftware,项目名称:OpenCVForUnity,代码行数:48,代码来源:MatchShapesSample.cs


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