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("前方有斑馬線"); } }
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(); } } }