我一直在研究一個有趣的編碼項目,它使用emguCV以及C#和.NET。我遇到的問題是試圖在我的代碼中初始化Capture()類。每次我嘗試初始化捕獲它拋出一個異常:emgu CV C#捕獲類
The Type initializer for 'Emgu.CV.CvInvoke' threw an Exception
Exception type: System.InitializationException from Emgu.CV.dll
這裏是C#代碼,我有:
class Vision
{
private Capture cap;
private HaarCascade haar;
private Form1 form;
public Vision()
{
form = new Form1();
cap = new Capture();
haar = new HaarCascade("C:\\haarcascade_frontalface_alt2.xml");
}
public void faceDetect()
{
using(Image<Bgr, Byte> nextFrame = cap.QueryFrame())
{
if(nextFrame != null)
{
Image<Gray, Byte> grayframe = nextFrame.Convert<Gray, Byte>();
var faces = grayframe.DetectHaarCascade(haar, 1.4, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(nextFrame.Width/8, nextFrame.Height/8))[0];
foreach(var face in faces)
{
nextFrame.Draw(face.rect, new Bgr(0, double.MaxValue, 0), 1);
}
form.setImage(nextFrame.ToBitmap());
}
}
}
}
的代碼的參考文獻:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;
using System.Drawing;
每次的發生異常,它顯示在 cap = new Capture();
我也嘗試將Capture類的攝像機索引設置爲0,1,2 ...並且沒有任何運氣。我也想過也許是因爲我有一個在Mac上運行的Windows,它沒有檢測到網絡攝像頭,但後來我下載了最新的Windows驅動程序以訪問攝像頭。我感謝所有提前幫助的人! :-)
EmguCV應該對OpenCV有一些非託管的依賴關係,你確定一切都安裝了嗎? – tbridge
是的,我下載了正確的軟件,並根據隨附的教程添加了依賴關係。 –
我知道,我necroposter,但在Emgu CV 310 Capture被VideoCapture取代。我失去了2天找到它。 –