我已经编写了使用 OpenCV 进行人脸检测的代码。我有视频文件,我正在根据特定的给定间隔从视频中提取图像,并对每个图像运行人脸检测。所以可能会有人站在相机前 5 分钟,图像提取间隔为 1 分钟的情况,因此对于接下来的 5 张图像,人将是相同的。那么我如何找出每个图像中的人是相同的还是不同的呢?下面是人脸检测的代码:
private static Rectangle[] DetectFace(Image<Bgr, Byte> image, string faceFileName)
{
if (GpuInvoke.HasCuda)
{
using (GpuCascadeClassifier face = new GpuCascadeClassifier(faceFileName))
{
using (GpuImage<Bgr, Byte> gpuImage = new GpuImage<Bgr, byte>(image))
using (GpuImage<Gray, Byte> gpuGray = gpuImage.Convert<Gray, Byte>())
{
Rectangle[] faceRegion = face.DetectMultiScale(gpuGray, 1.1, 10, Size.Empty);
return faceRegion;
}
}
}
else
{
//Read the HaarCascade objects
using (CascadeClassifier face = new CascadeClassifier(faceFileName))
{
using (Image<Gray, Byte> gray = image.Convert<Gray, Byte>()) //Convert it to Grayscale
{
//normalizes brightness and increases contrast of the image
gray._EqualizeHist();
//Detect the faces from the gray scale image and store the locations as rectangle
//The first dimensional is the channel
//The second dimension is the index of the rectangle in the specific channel
Rectangle[] facesDetected = face.DetectMultiScale(
gray,
1.1,
10,
new Size(filterWidth, filterHeight),
Size.Empty);
return facesDetected;
}
}
}
}