使用OpenCV为人脸识别生成唯一ID的代码

使用OpenCV为人脸识别生成唯一ID的代码,opencv,image-processing,emgucv,Opencv,Image Processing,Emgucv,我已经使用OpenCV编写了人脸检测代码。我有视频文件,我正在根据特定的给定间隔从视频中提取图像,并对每个图像运行人脸检测。因此,可能会有这样一种情况:一个人站在摄像机前5分钟,图像提取间隔为1分钟,因此对于接下来的5张图像,这个人将是相同的。那么,我怎样才能知道每个人的形象是相同的还是不同的呢?下面是人脸检测的代码: private static Rectangle[] DetectFace(Image<Bgr, Byte> image, string faceFileName)

我已经使用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;
                    }
                }
            }
        }
private static Rectangle[]DetectFace(图像图像,字符串faceFileName)
{           
if(GpuInvoke.HasCuda)
{
使用(GpuCascadeClassifier face=新的GpuCascadeClassifier(faceFileName))
{
使用(GpuImage GpuImage=新的GpuImage(图像))
使用(GpuImage gpuGray=GpuImage.Convert())
{
矩形[]面区域=面.DetectMultiScale(gpuGray,1.1,10,Size.Empty);
返回区;
}
}
}
其他的
{
//阅读HaarCascade对象
使用(CascadeClassifier face=新的CascadeClassifier(faceFileName))
{
使用(Image gray=Image.Convert())//将其转换为灰度
{
//标准化亮度并增加图像的对比度
灰色;
//从灰度图像中检测人脸,并将位置存储为矩形
//第一维度是通道
//第二个维度是特定通道中矩形的索引
矩形[]面检测=面检测多尺度(
灰色
1.1,
10,
新尺寸(过滤器宽度、过滤器高度),
尺寸(空);
检测返回面;
}
}
}
}

您可以通过计算最后N帧的中值来构建背景图像。 然后从每个新帧中减去背景,这样您只能看到更改。 试着大致识别人(例如通过斑点大小或形状)。 根据摄像机的帧率,你可以计算出某个人在摄像机前的平均时间


我想说得更准确些,但我们需要一些您已经尝试过的代码…

感谢分享您的想法,从每一帧中识别出人物,这些帧是从视频中生成的,因此它们不会完全相同。