// Update is called once per frame
        void Update()
        {
            if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
            {
                Mat rgbaMat = webCamTextureToMatHelper.GetMat();

                Imgproc.cvtColor(rgbaMat, grayMat, Imgproc.COLOR_RGBA2GRAY);

                bool result = detector.detect(grayMat, points);

                if (result)
                {
                    string decode_info = detector.decode(grayMat, points);

//                    Debug.Log (decode_info);
//                    Debug.Log (points.dump ());

                    // draw QRCode contour.
                    float[] points_arr = new float[8];
                    points.get(0, 0, points_arr);
                    Imgproc.line(rgbaMat, new Point(points_arr [0], points_arr [1]), new Point(points_arr [2], points_arr [3]), new Scalar(255, 0, 0, 255), 2);
                    Imgproc.line(rgbaMat, new Point(points_arr [2], points_arr [3]), new Point(points_arr [4], points_arr [5]), new Scalar(255, 0, 0, 255), 2);
                    Imgproc.line(rgbaMat, new Point(points_arr [4], points_arr [5]), new Point(points_arr [6], points_arr [7]), new Scalar(255, 0, 0, 255), 2);
                    Imgproc.line(rgbaMat, new Point(points_arr [6], points_arr [7]), new Point(points_arr [0], points_arr [1]), new Scalar(255, 0, 0, 255), 2);

                    Imgproc.putText(rgbaMat, "DECODE INFO: " + decode_info, new Point(5, grayMat.rows() - 10), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
                }

                Utils.fastMatToTexture2D(rgbaMat, texture);
            }
        }
Example #2
0
        // Update is called once per frame
        void Update()
        {
            if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
            {
                Mat rgbaMat = webCamTextureToMatHelper.GetMat();

                Imgproc.cvtColor(rgbaMat, grayMat, Imgproc.COLOR_RGBA2GRAY);

                bool result = detector.detect(grayMat, points);

                if (result)
                {
//                    Debug.Log (points.dump ());

                    float[] points_arr = new float[8];
                    points.get(0, 0, points_arr);

                    bool decode = true;
                    // Whether all points are in the image area or not.
                    for (int i = 0; i < 8; i = i + 2)
                    {
                        if (!imageSizeRect.contains(new Point(points_arr [i], points_arr [i + 1])))
                        {
                            decode = false;
//                            Debug.Log ("The point exists out of the image area.");
                            break;
                        }
                    }

                    // draw QRCode contour.
                    Imgproc.line(rgbaMat, new Point(points_arr [0], points_arr [1]), new Point(points_arr [2], points_arr [3]), new Scalar(255, 0, 0, 255), 2);
                    Imgproc.line(rgbaMat, new Point(points_arr [2], points_arr [3]), new Point(points_arr [4], points_arr [5]), new Scalar(255, 0, 0, 255), 2);
                    Imgproc.line(rgbaMat, new Point(points_arr [4], points_arr [5]), new Point(points_arr [6], points_arr [7]), new Scalar(255, 0, 0, 255), 2);
                    Imgproc.line(rgbaMat, new Point(points_arr [6], points_arr [7]), new Point(points_arr [0], points_arr [1]), new Scalar(255, 0, 0, 255), 2);

                    if (decode)
                    {
                        string decode_info = detector.decode(grayMat, points);
//                        Debug.Log (decode_info);
                        Imgproc.putText(rgbaMat, "DECODE INFO: " + decode_info, new Point(5, grayMat.rows() - 10), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
                    }
                }

                Utils.fastMatToTexture2D(rgbaMat, texture);
            }
        }
        private void Run()
        {
            Texture2D imgTexture = Resources.Load("link_github_ocv") as Texture2D;

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

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


            Mat grayMat = new Mat();

            Imgproc.cvtColor(imgMat, grayMat, Imgproc.COLOR_RGBA2GRAY);

            Mat points          = new Mat();
            Mat straight_qrcode = new Mat();

            QRCodeDetector detector = new QRCodeDetector();

            bool result = detector.detect(grayMat, points);

            if (result)
            {
                string decode_info = detector.decode(grayMat, points, straight_qrcode);

                Debug.Log(decode_info);
                Debug.Log(points.dump());
                Debug.Log(straight_qrcode.dump());

                // draw QRCode contour.
                float[] points_arr = new float[8];
                points.get(0, 0, points_arr);
                Imgproc.line(imgMat, new Point(points_arr [0], points_arr [1]), new Point(points_arr [2], points_arr [3]), new Scalar(255, 0, 0, 255), 2);
                Imgproc.line(imgMat, new Point(points_arr [2], points_arr [3]), new Point(points_arr [4], points_arr [5]), new Scalar(255, 0, 0, 255), 2);
                Imgproc.line(imgMat, new Point(points_arr [4], points_arr [5]), new Point(points_arr [6], points_arr [7]), new Scalar(255, 0, 0, 255), 2);
                Imgproc.line(imgMat, new Point(points_arr [6], points_arr [7]), new Point(points_arr [0], points_arr [1]), new Scalar(255, 0, 0, 255), 2);

                Imgproc.putText(imgMat, "DECODE INFO: " + decode_info, new Point(5, imgMat.rows() - 10), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
            }

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

            Utils.matToTexture2D(imgMat, texture);

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