看板 C_Sharp 關於我們 聯絡資訊
環境: EmguCV 2.4 IDE: VC# 2012 原本沒有寫在WPF中;跑出來正常的例子是。 這是視窗左邊 這是右邊 影片(load 進來的) | 一張圖片 然後就是影片會一直跑 這樣子~ 片段程式碼(這是ok的): Capture capture = new Capture("影片的位置"); ImageViewer viewer = new ImageViewer(); Application.Idle += new EventHandler(delegate(object sender, EventArgs e) { Image<Bgr, byte> frame = capture.QueryFrame(); viewer.Image = DrawMatches.Draw( "12.png", frame, out matchTime); }); viewer.ShowDialog(); 但我要寫在可以加入button的視窗,所以我就改成如下 Capture capture = new Capture("影片的位置"); Image<Bgr, Byte> resultImage; Application.Idle += new EventHandler(delegate(object sender, EventArgs e) { Image<Bgr, byte> frame = capture.QueryFrame(); resultImage = DrawMatches.Draw("12.png", frame, out matchTime); }); showImage.Source = ToBitmapSource(resultImage); //ToBitmapSource是轉型 showImage是xaml的框框 這邊會錯的的地方在於 "resultImage" 會不認識Application.Idle裡面的東西。 會有錯誤顯示 "使用了沒宣告的 resultImage"。 簡單來說 就是 resultImage = DrawMatches.Draw 根本看不到。 請問我要怎麼改呢??? 只要不加入Application.Idle 影片就只會一直停在第一個Frame。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.106.98 ※ 編輯: coal511464 來自: 140.123.106.98 (03/21 17:58) ※ 編輯: coal511464 來自: 140.123.106.98 (03/21 17:58) ※ 編輯: coal511464 來自: 140.123.106.98 (03/21 17:59) ※ 編輯: coal511464 來自: 140.123.106.98 (03/21 18:00) ※ 編輯: coal511464 來自: 140.123.106.98 (03/21 18:02)
KanoLoa:爛方法是把showImage也加進去一起做。 03/22 19:04
coal511464:我覺得不應該用IDLE...可找不到方法可以Capture 03/22 19:07
coal511464:然後一直跑FRAME 03/22 19:07
coal511464:其實我後來發現 他在背景其實有跑 但是在Mainwin 就是 03/22 19:08
coal511464:出不來 03/22 19:08
coal511464:如果把 showImage 加到IDLE裏頭 會無法顯示(但應該有跑 03/22 19:09
KanoLoa:加一個強制更新UI , this.update() 03/24 01:23
KanoLoa:也可以用BackgroundWorker去處理貼圖更新事件 03/24 01:25