Example #1
0
        private void detectHoughLineButton_Click(object sender, RoutedEventArgs e)
        {
            candidateHoughLineEquations.Clear();
            candidateHoughLineEquationsForReplay.Clear();
            candidateHoughLineEquations = ZebraCrossingDetector.DetectHoughLine(processingImg);

            //步驟用
            candidateHoughLineEquationsForReplay = candidateHoughLineEquations.ToList <LineEquation>();

            //Show Image
            LinkedListNode <LineEquation> node         = candidateHoughLineEquations.First;
            Image <Bgr, byte>             houghlineImg = oriImg.Clone();
            int colorIndex = 0;

            while (node != null)
            {
                houghlineImg.Draw(node.Value.Line, Utilities.LineColors[(colorIndex % Utilities.LineColors.Length)], 2);

                node = node.Next;
                colorIndex++;
            }

            houghLineViewer.Image = houghlineImg;
            houghLineViewer.Text  = "HoughLine 偵測畫面";
            houghLineViewer.Show();
        }
Example #2
0
        private void repairLinesButton_Click(object sender, RoutedEventArgs e)
        {
            candidateHoughLineEquations = ZebraCrossingDetector.RepairedLines(candidateHoughLineEquations, oriImg);

            //Show repaired Image
            showFinishedRepairedHoughLineImg = oriImg.Copy();
            int i = 0;
            //ToArray避開刪除後的List長度問題
            LinkedListNode <LineEquation> node = candidateHoughLineEquations.First;

            while (node != null)
            {
                //把線段畫上去
                showFinishedRepairedHoughLineImg.Draw(node.Value.Line, Utilities.LineColors[(i % Utilities.LineColors.Length)], 2);
                //下一個Node
                node = node.Next;
                i++;
            }

            repairedHoughLineViwer.Image = showFinishedRepairedHoughLineImg;
            repairedHoughLineViwer.Text  = "HoughLine 修復完成";
            if (repairedHoughLineViwer.Visible)
            {
                repairedHoughLineViwer.Hide(); //隱藏式窗,下次再show出
            }
            repairedHoughLineViwer.Show();
        }
Example #3
0
        private void AnalyzeBlackWhiteButton_Click(object sender, RoutedEventArgs e)
        {
            Image <Bgr, byte> stasticDst      = new Image <Bgr, byte>(640, 480, new Bgr(System.Drawing.Color.White));
            Image <Bgr, byte> drawScanLineImg = oriImg.Clone();
            bool isZebra = ZebraCrossingDetector.AnalyzeZebraCrossingTexture(mainDirectionLineGroupId, linesHistogram, processingImg, oriImg, stasticDst, drawScanLineImg);

            new ImageViewer(stasticDst, "統計圖表").Show();

            //Show Scan Line
            new ImageViewer(drawScanLineImg, "繪製掃描線路徑").Show();
            if (isZebra)
            {
                System.Windows.MessageBox.Show("前方有斑馬線");
            }
        }
Example #4
0
        /////////////////////////////////////////////////////////////////////////////////////
        private void loadImgButton_Click(object sender, RoutedEventArgs e)
        {
            string filename = OpenImgFile();

            if (filename != null)
            {
                oriImg           = ZebraCrossingDetector.LoadImg(filename);
                loadImgBox.Image = oriImg;

                //清空先前的資料
                candidateZebraCrossingsByHoughLine.Clear();

                //清空原先上一張偵測的圖
                crossingConnectionlines.Clear();

                repairedHoughLine.Clear();
                showFinishedRepairedHoughLineStepImg = oriImg.Copy();
                linesHistogram.Clear();
            }
        }
Example #5
0
        private void testVideoTimer_Tick(object sender, EventArgs e)
        {
            //如果有影片
            if (testVideoCapture != null)
            {
                if (isPlay)
                {
                    lock (this)
                    {
                        int currentFrameIndex = (int)testVideoCapture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES);
                        //如果Frame的index沒有差過影片的最大index
                        if (currentFrameIndex < videoTotalFrame)
                        {
                            Image <Bgr, byte> currentFrame = QueryFrameAndShow();
                            bool isZebra;
                            //處理辨識===========================================================
                            if (currentFrame != null && ((!isVideoZebra) || (isVideoZebra && (currentFrameIndex % 60 == 0))))
                            {
                                if ((isVideoZebra && (currentFrameIndex % 5 == 0)))
                                {
                                    isVideoZebra = false;
                                }

                                candidateHoughLineEquations.Clear();
                                Stopwatch watch = Stopwatch.StartNew();
                                oriImg        = ZebraCrossingDetector.ToCrop(currentFrame);
                                processingImg = ZebraCrossingDetector.ToGray(oriImg);
                                processingImg = ZebraCrossingDetector.MaskWhite(processingImg);
                                processingImg = ZebraCrossingDetector.PepperFilter(processingImg);
                                candidateHoughLineEquations = ZebraCrossingDetector.DetectHoughLine(processingImg);
                                candidateHoughLineEquations = ZebraCrossingDetector.RepairedLines(candidateHoughLineEquations, oriImg);
                                if (candidateHoughLineEquations.Count != 0)
                                {
                                    linesHistogram = ZebraCrossingDetector.MainGroupLineFilter(candidateHoughLineEquations, ref mainDirectionLineGroupId);

                                    Image <Bgr, byte> stasticDst      = new Image <Bgr, byte>(640, 480, new Bgr(System.Drawing.Color.White));
                                    Image <Bgr, byte> drawScanLineImg = oriImg.Clone();
                                    isZebra = ZebraCrossingDetector.AnalyzeZebraCrossingTexture(mainDirectionLineGroupId, linesHistogram, processingImg, oriImg, stasticDst, drawScanLineImg);
                                }
                                else
                                {
                                    isZebra = false;
                                }
                                watch.Stop();
                                Console.WriteLine("Crossing Analytics time = " + watch.ElapsedMilliseconds);

                                if (isVideoZebra != isZebra && isZebra)
                                {
                                    Console.WriteLine("前方有斑馬線");
                                    //voice.Speak("前方有斑馬線", SpeechVoiceSpeakFlags.SVSFlagsAsync);
                                    isVideoZebra = true;
                                    showIsCrossingTextBlock.Text = "前方有斑馬線";
                                    count++;
                                }
                                else
                                {
                                    showIsCrossingTextBlock.Text = "";
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("偵測次數" + count);
                            count = 0;
                            ResetVideo();
                        }
                    }
                }
                else if (isStop)
                {
                    //關閉,回到一開始畫面
                    ResetVideo();
                }
            }
        }
Example #6
0
 private void filterLinesButton_Click(object sender, RoutedEventArgs e)
 {
     linesHistogram = ZebraCrossingDetector.MainGroupLineFilter(candidateHoughLineEquations, ref mainDirectionLineGroupId);
 }
Example #7
0
        private void stepRepairLinesButton_Click(object sender, RoutedEventArgs e)
        {
            showSearchrepairedHoughLineStepImg = new Image <Bgr, byte>(oriImg.Width, oriImg.Height, new Bgr(System.Drawing.Color.Black));
            System.Drawing.Point p;
            //透過點擊按鈕來實現一步一步的迴圈方式觀看
            if (candiateLineEquation_i < candidateHoughLineEquationsForReplay.Count)
            {
                bool interset = false;
                if (candiateLineEquation_j < candidateHoughLineEquationsForReplay.Count)
                {
                    int           x = 0, y = 0;
                    LineSegment2D repairedLine = new LineSegment2D();
                    //預設資料都是0
                    Console.WriteLine(repairedLine.Length + "," + repairedLine.P1 + "," + repairedLine.P2);

                    //繪製正在比較有無共線或是相交的線段
                    showSearchrepairedHoughLineStepImg.Draw(candidateHoughLineEquationsForReplay[candiateLineEquation_i].Line, Utilities.LineColors[(candiateLineEquation_i % Utilities.LineColors.Length)], 1);
                    showSearchrepairedHoughLineStepImg.Draw(candidateHoughLineEquationsForReplay[candiateLineEquation_j].Line, Utilities.LineColors[(candiateLineEquation_j % Utilities.LineColors.Length)], 1);

                    //判斷是否共線或是相交的線段
                    interset = ZebraCrossingDetector.CheckIntersectOrNot(candidateHoughLineEquationsForReplay[candiateLineEquation_i], candidateHoughLineEquationsForReplay[candiateLineEquation_j], out p, ref repairedLine, oriImg);
                    if (interset)
                    {
                        showSearchrepairedHoughLineStepImg.Draw(new CircleF(new System.Drawing.PointF(x, y), 1), new Bgr(255, 255, 255), 1);

                        //改掉原先的線段
                        candidateHoughLineEquationsForReplay[candiateLineEquation_i].Line = repairedLine;
                        //並刪除被比較的線段
                        candidateHoughLineEquationsForReplay.RemoveAt(candiateLineEquation_j);
                    }
                    candiateLineEquation_j++;


                    repairedHoughLineStepViewer.Image     = showFinishedRepairedHoughLineStepImg;
                    searchRepairHoughLineStepViewer.Image = showSearchrepairedHoughLineStepImg;
                }
                else
                {
                    //並把這次比過的線段畫上去
                    showFinishedRepairedHoughLineStepImg.Draw(candidateHoughLineEquationsForReplay[candiateLineEquation_i].Line, Utilities.LineColors[(candiateLineEquation_i % Utilities.LineColors.Length)], 2);
                    //換到下一條比對的線段
                    candiateLineEquation_i++;
                    //都從0開始比,並跳過自己
                    candiateLineEquation_j = candiateLineEquation_i + 1;
                }
            }
            else
            {
                System.Windows.MessageBox.Show("檢測完畢");
                candiateLineEquation_i             = 0;
                candiateLineEquation_j             = candiateLineEquation_i + 1;
                showSearchrepairedHoughLineStepImg = new Image <Bgr, byte>(oriImg.Width, oriImg.Height, new Bgr(System.Drawing.Color.Black));
            }


            repairedHoughLineStepViewer.Text = "HoughLine 修復檢測完成";
            if (repairedHoughLineStepViewer.Visible)
            {
                repairedHoughLineStepViewer.Hide(); //隱藏式窗,下次再show出
            }
            repairedHoughLineStepViewer.Show();

            searchRepairHoughLineStepViewer.Text = "HoughLine 修復檢測";
            if (searchRepairHoughLineStepViewer.Visible)
            {
                searchRepairHoughLineStepViewer.Hide(); //隱藏式窗,下次再show出
            }
            searchRepairHoughLineStepViewer.Show();
        }
Example #8
0
 private void pepperfilter_Click(object sender, RoutedEventArgs e)
 {
     processingImg          = ZebraCrossingDetector.PepperFilter(processingImg);
     processingImgBox.Image = processingImg;
 }
Example #9
0
 private void maskWhiteButton_Click(object sender, RoutedEventArgs e)
 {
     processingImg          = ZebraCrossingDetector.MaskWhite(processingImg);
     processingImgBox.Image = processingImg;
 }
Example #10
0
 private void toGrayButton_Click(object sender, RoutedEventArgs e)
 {
     processingImg          = ZebraCrossingDetector.ToGray(oriImg);
     processingImgBox.Image = processingImg;
 }
Example #11
0
 private void cropImgButton_Click(object sender, RoutedEventArgs e)
 {
     oriImg           = ZebraCrossingDetector.ToCrop(oriImg);
     loadImgBox.Image = oriImg;
 }