問題描述
此時(shí)我有一個(gè)函數(shù),它從我的相機(jī)界面調(diào)用圖像.此圖像隨后會(huì)保存到硬盤驅(qū)動(dòng)器并顯示在 Windows 窗體 GUI 中.
At this point I have a function which calls for an image from my camera interface. This image is then saved to hard drive and also displayed in the Windows Forms GUI.
相機(jī)接口內(nèi)部返回圖像的函數(shù)如下:高度和寬度都是屬于相機(jī)接口類的整數(shù).在本例中,它們被設(shè)置為 800x600.
The function inside the camera interface which returns the image is as follows: height and width are both integers that are part of the camera interface class. In this case they were set to 800x600.
多次調(diào)用該函數(shù)首先表明捕獲幀花費(fèi)了相對(duì)較長的時(shí)間,導(dǎo)致程序在幾秒鐘內(nèi)無法使用.然后,在 Debug with Visual C# 2010 中運(yùn)行程序時(shí)捕獲了幾幀后,彈出 vshost.exe 的 windows 錯(cuò)誤:
Calling the function a number of times revealed first that capturing a frame took a comparatively long time, locking the program out of use for a few seconds. Then, after capturing a few frames while running the program in Debug with Visual C# 2010, a windows error popped up for vshost.exe:
然后我繼續(xù)發(fā)布應(yīng)用程序并從可執(zhí)行文件運(yùn)行它并收到錯(cuò)誤:
I then proceeded to publish the application and run it from the executable and got the error:
但是我也讓它與 Emgu.CV.CvInvoke.cvCreateCameraCapture(Int32) 拋出相同的異常.
However I have also had it throw the same exception with Emgu.CV.CvInvoke.cvCreateCameraCapture(Int32).
是什么導(dǎo)致了這些問題?如何避免它們?有沒有什么方法可以比現(xiàn)在更快地捕獲幀(當(dāng)它不崩潰時(shí))?
What is causing these problems? How can they be avoided? And is there any way to make capturing a frame faster than it currently does (when it doesn't crash)?
推薦答案
我看了你的代碼,我發(fā)現(xiàn)了問題.我期望它崩潰的原因是由于我建議的 using 語句抱歉:s.不完全是 using 語句.您似乎經(jīng)常訪問代碼以供系統(tǒng)處理.
I've looked at you code and I see the problem. The reason it crashes I expect is due to the using statement which I suggested Sorry :s. Well not exactly the using statement. You would appear to be accessing the code to often for the system to handle.
對(duì)少量代碼執(zhí)行大量操作.它不僅與您的相機(jī)建立通信,而且檢查它是否存在,處理驅(qū)動(dòng)程序并創(chuàng)建環(huán)形緩沖區(qū)等.現(xiàn)在,雖然給出的代碼確實(shí)確保只返回更新的圖像,但它通常只有在您使用按鈕或計(jì)時(shí)器時(shí)才能正常工作一段時(shí)間的延遲.現(xiàn)在,由于我知道您嘗試實(shí)現(xiàn)的目標(biāo),并且由于您想要的圖像比使用此方法可以合理實(shí)現(xiàn)的圖像更頻繁,因此您有一個(gè)更實(shí)用的選擇.
Does a large amount of operations for a small amount of code. Not only does it set up communication with your camera but checks it exists, handles drivers and creates ring buffers etc. Now while the code given does ensure only an updated image is returned it generally only works well if your using a button or a timer with a period of time delay. Now as I am aware of what your trying to achieve and since you want images more regularly than what can reasonably be achieved with this method you have a more practical option.
全局設(shè)置您的 Capture 設(shè)備并將其設(shè)置為記錄并調(diào)用 ProcessFrame 以盡可能從緩沖區(qū)獲取圖像.現(xiàn)在更改您的 QueryFrame 以復(fù)制它剛剛獲得的任何幀.這有望阻止您獲取前一幀的問題,并且您現(xiàn)在將從緩沖區(qū)中獲得最新的幀.
Set your Capture device up globally and set it of recording and calling ProcessFrame to get an image from the buffer whenever it can. Now change your QueryFrame simply to copy whatever frames its just acquired. This will hopefully stop your problem of getting the previous frame and you will now have the most recent frame out of the buffer.
希望這次能幫助您找到解決方案,抱歉,其他方法沒用,
Hope this helps get you to a solution this time, and sorry the other method was of no use,
干杯克里斯
這篇關(guān)于System.TypeInitializationException 在 C# 中使用 Emgu.CV的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!