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;
}
}
}
}