Это ошибка, которую я постоянно получаю: «Код серьезности Описание Состояние подавления строки файла проекта
Ошибка CS1503 Аргумент 1: невозможно преобразовать из «System.Drawing.Bitmap» в «byte[,» ,*]' MarkAttendanceSystemMVC C:\Users\IKUBIE\Documents\DMU 3rd Year\Development Project\MarkAttendanceSystemMVC\Services\FacialRecognitionService.cs 33 Активен
"
Это теперь код
using Emgu.CV;
using Emgu.CV.Structure;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
public class FacialRecognitionService
{
private readonly CascadeClassifier _faceCascade;
public FacialRecognitionService(string cascadeFilePath)
{
_faceCascade = new CascadeClassifier(cascadeFilePath);
}
public List DetectFaces(Stream imageStream)
{
// Convert the stream to a Bitmap
Bitmap bitmap;
try
{
imageStream.Position = 0; // Reset stream position to ensure it's read correctly
bitmap = new Bitmap(imageStream);
}
catch (Exception e)
{
throw new Exception("Could not convert stream to bitmap: " + e.Message);
}
// Convert the Bitmap to an Image
Image image = new Image(bitmap);
var faces = new List();
if (image != null)
{
// Perform the face detection
var detectedFaces = _faceCascade.DetectMultiScale(image, 1.1, 10, Size.Empty); // Adjust scale factor (1.1) and minNeighbors (10) according to your needs
faces.AddRange(detectedFaces);
}
return faces;
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... ap-to-byte