[程式] EmguCV 更新video frame 問題

看板C_Sharp (C#)作者 (coal)時間11年前 (2014/03/21 17:56), 編輯推噓0(008)
留言8則, 2人參與, 最新討論串1/1
環境: 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)

03/22 19:04, , 1F
爛方法是把showImage也加進去一起做。
03/22 19:04, 1F

03/22 19:07, , 2F
我覺得不應該用IDLE...可找不到方法可以Capture
03/22 19:07, 2F

03/22 19:07, , 3F
然後一直跑FRAME
03/22 19:07, 3F

03/22 19:08, , 4F
其實我後來發現 他在背景其實有跑 但是在Mainwin 就是
03/22 19:08, 4F

03/22 19:08, , 5F
出不來
03/22 19:08, 5F

03/22 19:09, , 6F
如果把 showImage 加到IDLE裏頭 會無法顯示(但應該有跑
03/22 19:09, 6F

03/24 01:23, , 7F
加一個強制更新UI , this.update()
03/24 01:23, 7F

03/24 01:25, , 8F
也可以用BackgroundWorker去處理貼圖更新事件
03/24 01:25, 8F
文章代碼(AID): #1JB0phiQ (C_Sharp)
文章代碼(AID): #1JB0phiQ (C_Sharp)