未从 Kinect Feed 中检测到面孔

Faces not getting detected from Kinect Feed

下面是我用于从 Kinect Feed 中检测人脸并将人脸像素设置为新图像的方法的代码。 .它由 GestureFlag 完成的手势触发。我从 FaceDetection class 调用的 Detect 方法取自 EMGU CV 样本。

 public string Detect(WriteableBitmap colorBitmap, int GestureFlag)
    {
        if(GestureFlag!=0)
        {
            List<Rectangle> faces = new List<Rectangle>();               
            Bitmap bitface = BitmapFromSource(colorBitmap);
            Image<Bgr, Byte> image = new Image<Bgr, Byte>(bitface);
            FaceDetection.Detect(image, "haarcascade_frontalface_default.xml",faces);
             Bitmap img = new Bitmap(@"C:\Users\rama\Downloads\kinect-2-background-removal-master\KinectBackgroundRemoval\Assets\emptyimage.png");
            img = ResizeImage(img, 1540, 1980);
            int high = image.Height;
            int width = image.Width;                
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < high; j++)
                {
                    Bgr pixel = image[j,i];
                    System.Drawing.Point p = new System.Drawing.Point(j,i);                    
                        if (faces[0].Contains(p) && i<1540 && j<1980)
                        {
                            img.SetPixel(i, j, System.Drawing.Color.FromArgb(255, (int)pixel.Blue, (int)pixel.Green,(int) pixel.Red));
                        }                   
                }
            }
            count++;
            key = count.ToString() + "rich.jpg";
            image.Save(@"C:\Users\rama\Downloads\kinect-2-background-removal-master\KinectBackgroundRemoval\Assets\"+key);
            img.Save(@"C:\Users\rama\Downloads\kinect-2-background-removal-master\KinectBackgroundRemoval\"+key);
            bool status = UploadToS3("nitish2", key, @"C:\Users\rama\Downloads\kinect-2-background-removal-master\KinectBackgroundRemoval\"+key);
            var FBClient = new FacebookClient();
            var UploadToFacebook = new FacebookUpload(FBClient, key);
            UploadToFacebook.Show();
            GestureFlag = 0;                      
         }
        return key;
    }

我遇到的问题 运行 是在我保存的新图像上打印了一组完全不同的像素。

基本上我认为问题出在这里:

FaceDetection.Detect(image, "haarcascade_frontalface_default.xml",faces);
for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < high; j++)
                {
                    Bgr pixel = image[j,i];
                    System.Drawing.Point p = new System.Drawing.Point(j,i);
                    if (faces[0].Contains(p) && i<1540 && j<1980)
                        {
                            img.SetPixel(i, j, System.Drawing.Color.FromArgb(255, (int)pixel.Blue, (int)pixel.Green,(int) pixel.Red));
                        }

                 }
            }

所以有人可以指出我哪里错了吗? 非常感谢。

EDITS :我已经尝试放置像 faces[0]!=null 这样的标志,它应该注意 FaceDetection.Detect 是否实际上返回任何东西,但我仍然得到相同的结果。

我还尝试保存 ColorBitmap 并针对 EMGU CV 样本对其进行测试,它可以轻松检测到图像中的人脸。

编辑 2:因此,我交叉检查了正在打印的矩形的坐标,以及正在检测的面部坐标和正在填充的 Rectangle() 的值。据我所知,它们几乎是一样的。所以运气不好。

我不知道我还能尝试调试什么。

如果有人能指出这一点那就太好了。

谢谢!

好的,我终于开始工作了。

问题是 Point[j,i] 应该是 Point[i,j]。我的 FaceDetection 方法也被证明有点不稳定,我也必须修复它才能最终正确调试我的代码。