[英]Convert type 'Emgu.CV.Mat' to 'Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte>'
[英]Can't convert from "Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>[]" to "Emgu.CV.IInputArray"
我正在嘗試構建一個簡單的面部/眼睛檢測 Windows 窗體應用程序。 我正在使用最新的 EmguCV (4.1.0),但是當我嘗試運行下面的代碼時,它給了我標題錯誤。 第二個錯誤涉及圖像 ID。
// Declaration at the beginning of the program
FaceRecognition = new EigenFaceRecognizer(80, double.PositiveInfinity);
FaceDetection = new CascadeClassifier(//Path to .xml haarcascade file);
Faces = new List<Image<Gray, byte>>();
IDs = new List<int>();
Webcam = new VideoCapture(0);
Frame = new Mat();
// Some code and some code
// Image detection and feeding it into the FaceRecognizer
Webcam.Retrieve(Frame);
var imageFrame = Frame.toImage<Gray, byte>();
// Some code (checking if imageFrame might be null etc.)
if (faces.Count() > 0){
var faces = FaceDetection.DetectMultiScale(imageFrame, 1.3, 5);
var processedImage = imageFrame.Copy(faces[0]).Resize(128, 150,
Emgu.CV.CvEnum.Inter.Cubic);
Faces.Add(processedImage);
IDs.Add(Convert.ToInt32(tbID.Text)); // ID for photo recognition (not really
neccesary)
}
else
{
// First method
var trainingFaces = (IInputArray) Faces; // Can't cast from List<Image<Gray, byte>> to IInputArray
var trainingIDs = (IInputArray) IDs; // Can't cast from int[] to IInputArray
FaceRecognition.Train(trainingFaces, trainingIDs);
// Second method
var trainingFaces = Faces.toArray();
var trainingIDs = IDs.toArray();
FaceRecognition.Train(trainingFaces, trainingIDs); // Can't convert from List<Image<Gray, byte>> to Emgu.CV.IInputArray.
這兩種方法都會出錯,我真的不知道如何修復它。
將訓練人臉圖像保留為 Mat 列表
List<Mat> TrainingFaces = new List<Mat>();
List<int> FaceIDs = new List<int>();
由於 IInputArray 可以構造為 VectorOfMat(Mat[]) 或 VectorOfInt(Int32) 那么它可以作為訓練參數傳遞:
FaceRecognition.Train( new VectorOfMat(TrainingFaces.ToArray()) , new VectorOfInt( FaceIDs.ToArray()) );
升級或降級您的 Emgu Lib
<package id="Emgu.CV" version="3.2.0.2721" targetFramework="net48" />
我的代碼現在作為你的代碼工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.