目前,我的EmguCV c#代码存在问题。我试图从数据库中识别我的图像,但它无法正常工作。一旦检测到我的面部,它的崩溃然后出现此错误
其他信息:OpenCV:不同大小的对象。
我尝试搜索此错误但我无能为力。
这是我的代码:
//Action for each element detected
foreach (MCvAvgComp f in facesDetected[0])
{
t = t + 1;
result = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
//draw the face detected in the 0th (gray) channel with blue color
currentFrame.Draw(f.rect, new Bgr(Color.Green), 2);
//Database select the image row and pass to the eigenobjectrecognizer
//ConnectToDatabase();
if (Connection.State.Equals(ConnectionState.Open))
{
Connection.Close();
TSTable.Clear();
ConnectToDatabase();
}
//Connection.Open();
OleDbCommand OledbSelect = new OleDbCommand("Select FaceName, FaceImage From TrainingSet1",Connection);
OleDbDataReader reader = OledbSelect.ExecuteReader();
while (reader.Read())
{
labels.Add(reader.GetValue(1).ToString());
trainingImages.Add(gray);
}
if (TSTable.Rows.Count != 0)
{
//TermCriteria for face recognition with numbers of trained images like maxIteration
MCvTermCriteria termCrit = new MCvTermCriteria(ContTrain, 0.001);
//Eigen face recognizer
EigenObjectRecognizer recognizer = new EigenObjectRecognizer(
trainingImages.ToArray(), //database faceimage list
labels.ToArray(), //facename list
3000,
ref termCrit);
name = recognizer.Recognize(result);
//Draw the label for each face detected and recognized
currentFrame.Draw(name, ref font, new Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.LightGreen));
}
我目前还是EmguCV和C#的新手。所以我不理解的一些例外情况。谁能帮我这个。
一旦代码中断,它就会转到EigenObjectRecognizer.cs
。这是它破坏的代码:
public static float[] EigenDecomposite(Image<Gray, Byte> src, Image<Gray, Single>[] eigenImages, Image<Gray, Single> avg)
{
return CvInvoke.cvEigenDecomposite(
src.Ptr,
Array.ConvertAll<Image<Gray, Single>, IntPtr>(eigenImages, delegate(Image<Gray, Single> img) { return img.Ptr; }),
avg.Ptr);
}
答案 0 :(得分:1)
我猜,问题出在trainingImages
。每个特征图像的宽度和高度必须与输入图像的宽度和高度相同。
您的结果图片尺寸为100x100。因此,您的所有trainingImage
都应该具有相同的尺寸。在添加到列表之前调整它们的大小。
我查看了您的代码。麻烦仍然是大小。 第305行替换为:
result = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(gray.Width, gray.Height, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);