Esempio n. 1
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();
                }
            }
        }
Esempio n. 2
0
 private void filterLinesButton_Click(object sender, RoutedEventArgs e)
 {
     linesHistogram = ZebraCrossingDetector.MainGroupLineFilter(candidateHoughLineEquations, ref mainDirectionLineGroupId);
 }