Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用摄像机的面部检测坐标_C#_Windows Phone 8.1 - Fatal编程技术网

C# 使用摄像机的面部检测坐标

C# 使用摄像机的面部检测坐标,c#,windows-phone-8.1,C#,Windows Phone 8.1,我需要一种方法在摄像头视图中获取C#for Windows Phone 8.1中人脸的坐标。我在网上找不到任何东西,所以我想这可能是不可能的。我需要的是在摄影机视图中检测到的人脸周围形成的“长方体”的x和y(可能还有面积)。以前有人这样做过吗?代码片段(请记住,这是我在代码下面链接的教程中的应用程序的一部分。它不可复制粘贴,但应该提供一些帮助) const string MODEL_FILE=“haarcascade\u frontalface\u alt.xml”; FaceDetection

我需要一种方法在摄像头视图中获取C#for Windows Phone 8.1中人脸的坐标。我在网上找不到任何东西,所以我想这可能是不可能的。我需要的是在摄影机视图中检测到的人脸周围形成的“长方体”的x和y(可能还有面积)。以前有人这样做过吗?

代码片段(请记住,这是我在代码下面链接的教程中的应用程序的一部分。它不可复制粘贴,但应该提供一些帮助)

const string MODEL_FILE=“haarcascade\u frontalface\u alt.xml”;
FaceDetectionWinPhone.Detector m_Detector;
公共主页()
{
初始化组件();
m_detector=newfacedetectionwinphone.detector(System.Xml.Linq.XDocument.Load(MODEL_文件));
}
无效photoChooserTask_已完成(对象发送方,PhotoResult e)
{
if(e.TaskResult==TaskResult.OK)
{
BitmapImage bmp=新的BitmapImage();
bmp.SetSource(e.ChosenPhoto);
WriteableBitmap btmMap=新的WriteableBitmap(bmp);
//从图像中查找面
列表面=
m_检测器(
btmMap,10f,1f,0.05f,1,假,假);
//穿过每个面,在上面画一个红色矩形。
foreach(面中的变量r)
{
int x=转换为32(r.x);
int y=转换为32(r.y);
int-width=转换为32(r.width);
int高度=转换为32(r高度);
填充矩形(x,y,x+高度,y+宽度,System.Windows.Media.Colors.Red);
}
//在绘制位图之前更新它。
btmMap.Invalidate();
facesPic.Source=btmMap;
}
}
这是从

要实时执行此操作,您需要截取取景器图像,可能需要使用
NewCameraFrame
方法(编辑:不确定是否应使用此方法或
PhotoCamera.GetPreviewBufferArgb32
,如下所述。我必须让您自行研究) 因此,基本上你的任务有两个部分:

  • 获取取景器图像
  • 检测上面的面(使用类似于上面代码的东西)
  • 如果我是你,我会先做第二步。在从磁盘加载的图像上,一旦你们能检测到上面的人脸,我将看到如何获取当前取景器图像并检测上面的人脸。十、 一旦检测到人脸,Y坐标就很容易获得——请参见上面的代码

    (编辑):我认为您应该尝试使用
    PhotoCamera.GetPreviewBufferArgb32
    方法获取取景器图像。看这里。此外,请确保搜索MSDN文档和教程。这应该足以完成步骤1


    很多人脸检测算法都使用Haar分类器、Viola-Jones算法等。如果你熟悉这些,你会对自己所做的事情更有信心,但你可以不用它们。另外,请阅读我链接的材料-它们看起来相当不错。

    可能是@venerik的副本,而不是副本。这是一张静态照片。我说的是相机。重复问题的答案,如果你选择阅读它的话,同时涉及图像和相机。答案是:“人脸跟踪:此模块在实时视频流中实时定位人脸位置。”…感谢您的想法。这太完美了!我从来没有这样想过。我很乐意帮忙。另外,我稍微编辑了一下这篇文章,提到了PhotoCamera类,您可以使用它在步骤(1)中获得良好的效果。还有其他细微的变化(例如,关于提供的代码段的备注)
    const string MODEL_FILE = "haarcascade_frontalface_alt.xml";
    FaceDetectionWinPhone.Detector m_detector;
    public MainPage()
    {
       InitializeComponent();
       m_detector = new FaceDetectionWinPhone.Detector(System.Xml.Linq.XDocument.Load(MODEL_FILE));
    }
    
    void photoChooserTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)  
        {
            BitmapImage bmp = new BitmapImage();
            bmp.SetSource(e.ChosenPhoto);
            WriteableBitmap btmMap = new WriteableBitmap(bmp);
    
            //find faces from the image
            List<FaceDetectionWinPhone.Rectangle> faces =
                 m_detector.getFaces(
                 btmMap, 10f, 1f, 0.05f, 1, false, false);
    
            //go through each face, and draw a red rectangle on top of it.
            foreach (var r in faces)
            {
                int x = Convert.ToInt32(r.X);
                int y = Convert.ToInt32(r.Y);
                int width = Convert.ToInt32(r.Width);
                int height = Convert.ToInt32(r.Height);
                btmMap.FillRectangle(x, y, x + height, y + width, System.Windows.Media.Colors.Red);
             }
            //update the bitmap before drawing it.
            btmMap.Invalidate();
            facesPic.Source = btmMap;
        }
    }