【问题标题】:Additional information: OpenCV: Different sizes of objects using c#附加信息:OpenCV:使用 c# 的不同大小的对象
【发布时间】:2015-08-10 11:48:41
【问题描述】:

目前,我的 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);
  }

【问题讨论】:

    标签: c# opencv emgucv


    【解决方案1】:

    我猜,问题出在trainingImages。每个 eigenImage 的宽高必须与输入图像的宽高相同。

    您的结果图片大小为 100x100。所以,你所有的trainingImage 应该有相同的大小。在添加到您的列表之前调整它们的大小。

    我查看了您的代码。麻烦还在大小上。 第 305 行替换为:

    result = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(gray.Width, gray.Height, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
    

    【讨论】:

    • 还是因为这行代码trainingImages.Add(gray);
    • 我不知道你把gray变量放在哪里了。但是您应该将此图像调整为与您的result 图像相同的大小。更新了答案。
    • 也许你想看看this。非常感谢您的帮助...
    • 更新我的答案。请检查一下。
    • 问题仍然存在 :) 更新了答案,检查一下。
    猜你喜欢
    • 1970-01-01
    • 2011-04-27
    • 2023-04-03
    • 1970-01-01
    • 2020-05-26
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多