Exemple #1
0
        /// <summary>
        /// 繪製黑白交錯的曲線(縱軸是Intensity,橫軸是排序的線段從最前面的線段到最下面的線段的座標)
        /// </summary>
        /// <param name="drawImg"></param>
        /// <param name="current">現在的座標像素</param>
        /// <param name="previous">前一個點的座標像素</param>
        /// <param name="x">x軸步近的值</param>
        private static void DrawBlackWhiteCurve(Image <Bgr, byte> drawImg, IntensityPoint current, IntensityPoint previous, int x)
        {
            //繪製呈現用,斑馬線黑白像素經過的圖形
            int projectY = Math.Abs((int)current.GetIntensity() - 300);

            if (!current.IsEmpty() && !previous.IsEmpty())
            {
                float prevPorjectY = Math.Abs((float)previous.GetIntensity() - 300);
                drawImg.Draw(new LineSegment2DF(new PointF(x - 2, projectY), new PointF(x, prevPorjectY)), new Bgr(Color.Green), 1);
            }
            else
            {
                drawImg.Draw(new LineSegment2DF(new PointF(0, 300), new PointF(x, projectY)), new Bgr(Color.Red), 1);
            }
            drawImg.Draw(new CircleF(new PointF(x, projectY), 1), new Bgr(Color.Blue), 2);
        }
Exemple #2
0
        private static bool DoBlackWhiteStatisticsByScanLine(List <LineSegment2DF> lines, Image <Gray, byte> source, Image <Bgr, byte> stasticDst)
        {
            string            checkBlackWhiteCrossingPoint = "";
            Image <Bgr, byte> blackWhiteCurveImg           = new Image <Bgr, byte>(480, 300, new Bgr(Color.White));
            int            x = 0; // 要尋訪的起點
            IntensityPoint current, previous;

            current  = new IntensityPoint();
            previous = new IntensityPoint();

            //記錄每一條線段的像素統計用的索引

            int pixelSum                = 0;
            int previousPixelValue      = -1;
            int previousCheckIntentisty = -1;

            //計算線段通過pixel
            foreach (LineSegment2DF line in lines)
            {
                float nextX;
                float nextY = line.P1.Y;

                //如果尋訪小於線段結束點的y軸,則不斷尋訪
                while (nextY < line.P2.Y)
                {
                    nextX = GetXPositionFromLineEquations(line.P1, line.P2, nextY);

                    //抓灰階 or 二值化做測試
                    Gray pixel = source[Convert.ToInt32(nextY), Convert.ToInt32(nextX)];
                    CheckBlackWhiteTexture(checkBlackWhiteCrossingPoint, pixel.Intensity, ref pixelSum, ref previousPixelValue, ref previousCheckIntentisty, ref checkBlackWhiteCrossingPoint);

                    //取得目前掃描線步進的素值
                    current.SetData(new PointF(nextX, nextY), pixel.Intensity);

                    if (stasticDst != null)
                    {
                        DrawBlackWhiteCurve(stasticDst, current, previous, x);
                    }

                    //設定前一筆
                    previous.SetData(current.GetLocation(), current.GetIntensity());

                    //Console.WriteLine("x:" + nextX + ",y:" + nextY + ",Intensity:" + pixel.Intensity);

                    //步進Y
                    nextY++;
                    //繪製用的步進值
                    x += 5;
                }
            }

            ////顯示所有check的狀況
            Console.WriteLine(checkBlackWhiteCrossingPoint);
            if (checkBlackWhiteCrossingPoint.Contains("01010") || checkBlackWhiteCrossingPoint.Contains("10101"))
            {
                Console.WriteLine("有交錯");
                return(true);
            }
            else
            {
                return(false);
            }
        }