【发布时间】:2015-08-16 10:44:28
【问题描述】:
以下是我用于从 Kinect Feed 中检测人脸然后将人脸像素设置为新图像的方法的代码。 .它由 GestureFlag 完成的手势触发。我从FaceDetection 类调用的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));
}
}
}
那么有人可以指出我哪里出错了吗? 非常感谢。
编辑:我尝试放置像faces[0]!=null 这样的标志,它应该注意FaceDetection.Detect 是否实际上返回任何东西,但我仍然得到相同的结果。
我还尝试保存 ColorBitmap 并针对 EMGU CV 样本进行测试,它可以轻松检测到图像中的人脸。
编辑 2:所以我交叉检查了正在打印的矩形的坐标,其中包含被检测到的面部坐标和正在填充的 Rectangle() 的值。据我所知,它们几乎相同。所以没有运气。
我不知道我还能尝试什么来调试。
如果有人能指出这一点,那就太好了。
谢谢!
【问题讨论】:
标签: c# kinect emgucv face-detection