Esempio n. 1
0
        private CvLineSegmentPoint[] detectLinesFromFeatures(CvMat hue, CvMat roi)
        {
            // IDEA 3 :
            // Extract features (actual box corners?!) from ROI with corner detection
            CvPoint2D32f[] corners;                // extracted features
            int            cornerCount;            // not exactly "count", but rather "maximum number of corners to return"
            double         qualityLevel    = 0.05; // this changes to 0.1 if NOT using ROI as mask!
            double         minimumDistance = 25;   // maybe this has to be a percentage of the input-size, rather than an absolute value?!?!?
            bool           useHarris       = false;
            int            blockSize       = 3;

            // NOTE : roi is not as good to check for features as the hue itself!!!
#if false
            cornerCount = 100;
            Cv.GoodFeaturesToTrack(
                roi, MatOps.CopySize(roi, MatrixType.F32C1, Const.ScalarBlack), MatOps.CopySize(roi, MatrixType.F32C1, Const.ScalarBlack),
                out corners, ref cornerCount, qualityLevel, minimumDistance, null, blockSize, useHarris);
            CvMat roiClone = roi.Clone();
            roiClone.SaveImage("roiClone.png");
            for (int i = 0; i < cornerCount; ++i)
            {
                // remove "isolated" features : gave back some good results, but it still wasn't as good as actual HUE feature discovery
                CvPoint2D32f feature = corners[i];
                if (checkFeatureArea(roiClone, feature))
                {
                    roiClone.Circle(feature, 10, 127);
                }
            }
            MatOps.NewWindowShow(roiClone, "ROI!");
            Console.WriteLine("corners=" + cornerCount);
#endif

            // TODO : determine if it's a good idea to use ROI as a mask.
            // NOTE : Abandoning this idea for now. Good features are truly found, but they give worse lines than [IDEA 4]!
            cornerCount = 100;
            Cv.GoodFeaturesToTrack(
                hue, MatOps.CopySize(roi, MatrixType.F32C1, Const.ScalarBlack), MatOps.CopySize(roi, MatrixType.F32C1, Const.ScalarBlack),
                out corners, ref cornerCount, qualityLevel, minimumDistance, roi, blockSize, useHarris);
            //CvMat hueClone = hue.Clone();
            CvMat hueClone = MatOps.CopySize(hue, MatrixType.U8C1, 0);
            for (int i = 0; i < cornerCount; ++i)
            {
                hueClone.Circle(corners[i], 10, 127, -1);
            }
            CvLineSegmentPoint[] lines2 = hueClone.HoughLinesProbabilistic(1, 1 * Cv.PI / 180, 75, 1, 10000);
            for (int i = 0; i < lines2.Length; ++i)
            {
                hueClone.Line(lines2[i].P1, lines2[i].P2, Const.ScalarRandom(), 3, LineType.AntiAlias);
            }
            MatOps.NewWindowShow(hueClone, "Lines from Features");

            Console.WriteLine("=======================");
            Console.WriteLine("detectLinesFromFeatures");
            Console.WriteLine("corners=" + cornerCount);
            Console.WriteLine("lines=" + lines2.Length);
            Console.WriteLine("=======================");

            return(lines2);
        }
Esempio n. 2
0
        static void showrite(String s, CvMat image)
        {
            CvWindow window = new CvWindow(showiteCounter.ToString() + s);
            window.ShowImage(image);
            image.SaveImage(showiteCounter.ToString() + s + ".png");

            showiteCounter++;
        }
        /// <summary>
        /// 各Kinect情報の画像を保存する
        /// </summary>
        /// <param name="frameNo"></param>
        /// <param name="colorPixels"></param>
        /// <param name="depthBuffer"></param>
        /// <param name="bodyIndexBuffer"></param>
        private void SaveImages(int frameNo, ref byte[] colorPixels, ref ushort[] depthBuffer, ref byte[] bodyIndexBuffer)
        {
            string path         = Path.Combine(this.dataDir, frameNo.ToString());
            CvMat  colorOrigMat = Utility.ColorArrayToCvMat(this.colorWidth, this.colorHeight, ref colorPixels);
            CvMat  depthMat     = Utility.DpethArrayToCvMat(this.depthWidth, this.depthHeight, ref depthBuffer);
            CvMat  bodyIndexMat = Utility.BodyIndexArrayToCvMat(this.depthWidth, this.depthHeight, ref bodyIndexBuffer);
            CvMat  colorMat     = new CvMat(this.colorHeight / 2, this.colorWidth / 2, MatrixType.U8C4);

            Cv.Resize(colorOrigMat, colorMat, Interpolation.NearestNeighbor); // THIS IS A BOTTLENECK!!!
            Task.Run(() => colorMat.SaveImage(path + "_color.jpg", new ImageEncodingParam(ImageEncodingID.JpegQuality, 85)));
            Task.Run(() => depthMat.SaveImage(path + "_depth.png", new ImageEncodingParam(ImageEncodingID.PngCompression, 5)));
            Task.Run(() => bodyIndexMat.SaveImage(path + "_user.png", new ImageEncodingParam(ImageEncodingID.PngCompression, 5)));
        }
 /// <summary>
 /// 各Kinect情報の画像を保存する
 /// </summary>
 /// <param name="frameNo"></param>
 /// <param name="colorPixels"></param>
 /// <param name="depthBuffer"></param>
 /// <param name="bodyIndexBuffer"></param>
 private void SaveImages(int frameNo, ref byte[] colorPixels, ref ushort[] depthBuffer, ref byte[] bodyIndexBuffer)
 {
     string path = Path.Combine(this.dataDir, frameNo.ToString());
     CvMat colorOrigMat = Utility.ColorArrayToCvMat(this.colorWidth, this.colorHeight, ref colorPixels);
     CvMat depthMat = Utility.DpethArrayToCvMat(this.depthWidth, this.depthHeight, ref depthBuffer);
     CvMat bodyIndexMat = Utility.BodyIndexArrayToCvMat(this.depthWidth, this.depthHeight, ref bodyIndexBuffer);
     CvMat colorMat = new CvMat(this.colorHeight / 2, this.colorWidth / 2, MatrixType.U8C4);
     Cv.Resize(colorOrigMat, colorMat, Interpolation.NearestNeighbor); // THIS IS A BOTTLENECK!!!
     Task.Run(() => colorMat.SaveImage(path + "_color.jpg", new ImageEncodingParam(ImageEncodingID.JpegQuality, 85)));
     Task.Run(() => depthMat.SaveImage(path + "_depth.png", new ImageEncodingParam(ImageEncodingID.PngCompression, 5)));
     Task.Run(() => bodyIndexMat.SaveImage(path + "_user.png", new ImageEncodingParam(ImageEncodingID.PngCompression, 5)));
 }