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(); }
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(); } } }