示例#1
0
        private CvLineSegmentPoint[] detectLinesFromCanny(CvMat roi)
        {
            CvMat edgesMat = MatOps.CopySize(roi, MatrixType.U8C1);

            roi.Canny(edgesMat, 10, 200, ApertureSize.Size3); // Size5 also works good; 7 not; rest crash!
            // these values work fine with "box7.png"
            double rho       = 1;                             // 1
            double theta     = 1 * Cv.PI / 180;               // 1*Cv.PI/180
            int    threshold = 75;                            // 75 (quality)
            double minLength = 1;                             // 1
            double maxGap    = 10000;                         // 1000000, but not Infinity, for some dumb reason

            CvLineSegmentPoint[] lines = edgesMat.HoughLinesProbabilistic(rho, theta, threshold, minLength, maxGap);
            CvMat linesMat             = MatOps.CopySize(edgesMat, MatrixType.U8C3, 0);

            for (int i = 0; i < lines.Length; ++i)
            {
                linesMat.Line(lines[i].P1, lines[i].P2, Const.ScalarRandom(), 3, LineType.AntiAlias);
            }

            //MatOps.NewWindowShow( edgesMat, "edgesMat Canny-Hough" );
            MatOps.NewWindowShow(linesMat, "linesMat");
            Console.WriteLine("====================");
            Console.WriteLine("detectLinesFromCanny");
            Console.WriteLine("lines=" + lines.Length);
            Console.WriteLine("====================");

            return(lines);
        }