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


C# Mat.ToString方法代码示例

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


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

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

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

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

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

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

示例6: HDR

        private static void HDR()
        {
            var hdr = CalibrateDebevec.Create();

            Mat[] images = new Mat[3];
            images[0] = Cv2.ImRead(@"data\lenna.png", ImreadModes.AnyColor);
            images[1] = Cv2.ImRead(@"data\lenna.png", ImreadModes.AnyColor);
            images[2] = Cv2.ImRead(@"data\lenna.png", ImreadModes.AnyColor);

            float[] speeds = new float[3];
            speeds[0] = 1;
            speeds[1] = 1;
            speeds[2] = 1;

            Mat dst = new Mat();

            hdr.Process(images, dst, speeds);

            dst.ToString();

            for (int i = 0; i < Math.Max(dst.Rows, dst.Cols); i++)
            {
                Console.WriteLine(dst.At<float>(i));
            }
        }
开发者ID:JiphuTzu,项目名称:opencvsharp,代码行数:25,代码来源:Program.cs

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

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

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

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

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

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

示例13: Start

        // Use this for initialization
        void Start()
        {
            Dictionary dictionary = Aruco.getPredefinedDictionary (dictionaryId);

            Mat markerImg = new Mat ();
            Aruco.drawMarker (dictionary, markerId, markerSize, markerImg, borderBits);

            Debug.Log ("markerImg.ToString() " + markerImg.ToString ());

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

            Utils.matToTexture2D (markerImg, texture);

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

            //save markerImg
            //                      string savePath = Application.persistentDataPath + "/marker_id" + markerId + ".jpg";
            //                      Debug.Log ("savePath " + savePath);
            //                      Imgcodecs.imwrite (savePath, markerImg);
        }
开发者ID:EnoxSoftware,项目名称:OpenCVForUnity,代码行数:21,代码来源:ArUcoCreateMarkerSample.cs

示例14: Start

        // Use this for initialization
        void Start()
        {
            Texture2D srcTexture = Resources.Load ("template") as Texture2D;
                        Texture2D dstTexture = Resources.Load ("lena") as Texture2D;
                        Mat src = new Mat (srcTexture.height, srcTexture.width, CvType.CV_8UC3);
                        Mat dst = new Mat (dstTexture.height, dstTexture.width, CvType.CV_8UC3);
                        Utils.texture2DToMat (srcTexture, src);
                        Utils.texture2DToMat (dstTexture, dst);

                        Mat mask = new Mat (src.rows (), src.cols (), CvType.CV_8UC1, new Scalar (255));
                        Mat result = new Mat ();

                        Point point = new Point (315, 450);
                        Photo.seamlessClone (src, dst, mask, point, result, Photo.NORMAL_CLONE);

                        Debug.Log ("result ToString " + result.ToString ());

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

                        Utils.matToTexture2D (result, texture);

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

示例15: Start

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

            Mat image = new Mat (imageTexture.height, imageTexture.width, CvType.CV_8UC3);

            Utils.texture2DToMat (imageTexture, image);
            Debug.Log ("image.ToString() " + image.ToString ());

            Texture2D maskTexture = Resources.Load ("lena_grabcut_mask") as Texture2D;

            Mat mask = new Mat (imageTexture.height, imageTexture.width, CvType.CV_8UC1);

            Utils.texture2DToMat (maskTexture, mask);
            Debug.Log ("mask.ToString() " + mask.ToString ());

            OpenCVForUnity.Rect rectangle = new OpenCVForUnity.Rect (10, 10, image.cols () - 20, image.rows () - 20);

            Mat bgdModel = new Mat (); // extracted features for background
            Mat fgdModel = new Mat (); // extracted features for foreground

            convertToGrabCutValues (mask); // from grayscale values to grabcut values

            int iterCount = 5;
            //          Imgproc.grabCut (image, mask, rectangle, bgdModel, fgdModel, iterCount, Imgproc.GC_INIT_WITH_RECT);
            Imgproc.grabCut (image, mask, rectangle, bgdModel, fgdModel, iterCount, Imgproc.GC_INIT_WITH_MASK);

            convertToGrayScaleValues (mask); // back to grayscale values
            Imgproc.threshold (mask, mask, 128, 255, Imgproc.THRESH_TOZERO);

            Mat foreground = new Mat (image.size (), CvType.CV_8UC3, new Scalar (0, 0, 0));
            image.copyTo (foreground, mask);

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

            Utils.matToTexture2D (foreground, texture);

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


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