예제 #1
0
    //HOGDetect를 통해 사람 확인
    void Update()
    {
        tex2   = MakeTexture2D(carm.targetTexture);
        rgbMat = new Mat(tex2.height, tex2.width, CvType.CV_8UC3);

        Utils.texture2DToMat(tex2, rgbMat);

        int frameWidth  = rgbMat.cols();
        int frameHeight = rgbMat.rows();

        colors = new Color32[frameWidth * frameHeight];

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

        using (MatOfRect locations = new MatOfRect())
            using (MatOfDouble weights = new MatOfDouble())
            {
                des.setSVMDetector(HOGDescriptor.getDefaultPeopleDetector());
                des.detectMultiScale(rgbMat, locations, weights);

                OpenCVForUnity.Rect[] rects = locations.toArray();
                for (int i = 0; i < rects.Length; i++)
                {
                    Imgproc.rectangle(rgbMat, 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), 2);
                }
            }

        Texture2D texture = new Texture2D(320, 160, TextureFormat.ARGB32, false);

        Utils.matToTexture2D(rgbMat, texture, colors);

        GameObject.Find("test2").GetComponent <Renderer>().material.mainTexture = texture;
    }
        // Update is called once per frame
        void Update()
        {
            if (sourceToMatHelper.IsPlaying() && sourceToMatHelper.DidUpdateThisFrame())
            {
                Mat rgbMat = sourceToMatHelper.GetMat();

                using (MatOfRect locations = new MatOfRect())
                    using (MatOfDouble weights = new MatOfDouble())
                    {
                        des.setSVMDetector(HOGDescriptor.getDefaultPeopleDetector());
                        des.detectMultiScale(rgbMat, locations, weights);

                        OpenCVForUnity.CoreModule.Rect[] rects = locations.toArray();
                        for (int i = 0; i < rects.Length; i++)
                        {
                            //Debug.Log ("detected person " + rects [i]);
                            Imgproc.rectangle(rgbMat, 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), 2);
                        }
                        //Debug.Log (locations.ToString ());
                        //Debug.Log (weights.ToString ());

                        Utils.fastMatToTexture2D(rgbMat, texture);
                    }
            }
        }
예제 #3
0
        // Update is called once per frame
        void Update()
        {
            //Loop play
            if (capture.get(Videoio.CAP_PROP_POS_FRAMES) >= capture.get(Videoio.CAP_PROP_FRAME_COUNT))
            {
                capture.set(Videoio.CAP_PROP_POS_FRAMES, 0);
            }

            //error PlayerLoop called recursively! on iOS.reccomend WebCamTexture.
            if (capture.grab())
            {
                capture.retrieve(rgbMat, 0);

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

                //Debug.Log ("Mat toString " + rgbMat.ToString ());

                using (HOGDescriptor des = new HOGDescriptor())
                    using (MatOfRect locations = new MatOfRect())
                        using (MatOfDouble weights = new MatOfDouble()) {
                            des.setSVMDetector(HOGDescriptor.getDefaultPeopleDetector());
                            des.detectMultiScale(rgbMat, locations, weights);

                            OpenCVForUnity.Rect[] rects = locations.toArray();
                            for (int i = 0; i < rects.Length; i++)
                            {
//												Debug.Log ("detected person " + rects [i]);
                                Imgproc.rectangle(rgbMat, 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), 2);
                            }
//										Debug.Log (locations.ToString ());
//										Debug.Log (weights.ToString ());
                        }


                Utils.matToTexture2D(rgbMat, texture);

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