简体   繁体   English

如何从面部检测方块获得“面部照片”?

[英]How to obtain a “mugshot” from face detection squares?

I'm building an application that will take an image of a single person's whole body and will produce a "mugshot" for that person. 我正在构建一个应用程序,它将拍摄一个人的整个身体的图像,并将为该人产生一个“照片”。

Mugshot meaning an image of the person's whole face, neck, hair and ears at the same general size of another mugshot. Mugshot意味着一个人的整个脸,脖子,头发和耳朵的图像与另一个照片的大小相同。

Currently I'm using 目前我正在使用
http://askernest.com/archive/2008/05/03/face-detection-in-c.aspx http://askernest.com/archive/2008/05/03/face-detection-in-c.aspx
to implement OpenCV and I'm using 实现OpenCV,我正在使用

harrcascade_frontalface_default.xml  
harrcascade_frontalface_alt.xml  
harrcascade_frontalface_alt2.xml  
harrcascade_frontalface_alt_tree.xml

as my cascades. 作为我的级联。

I use all of the cascades because a single one will not detect all my faces. 我使用了所有级联,因为单个级联不会检测到我的所有脸。 After I get all of the faces detected by all of the cascades I find my average square and use that for my final guess of how tall and wide the mugshot should be. 在我得到所有级联检测到的所有面部后,我找到了我的平均正方形,然后使用它来判断我的最终应该是什么样的高度和宽度。

My problem is 3 parts. 我的问题是3部分。

  • My current process is rather slow. 我目前的过程相当缓慢。 How can I speed up the detection process? 如何加快检测过程?
    Edit: I'm finding that the processing time is directly related to photo size. 编辑:我发现处理时间与照片尺寸直接相关。 Reducing the size of the photos may prove to be helpful. 减少照片的大小可能会有所帮助。

  • A single cascade will not detect all the faces I come across so I'm using all of them. 单个级联不会检测到我遇到的所有面孔,所以我正在使用它们。 This of course produces many varied squares and a few false positives. 这当然会产生许多不同的方块和一些误报。 What method can I use to identify false positives and leave them out of the average square calculation? 我可以使用什么方法来识别误报并将其排除在平均平方计算之外? ex. 恩。 桑德曼韦恩
    Edit : I'm implementing an average of values within standard deviation. 编辑:我正在实现标准偏差范围内的平均值。 Will post code soon. 将尽快发布代码。

  • I'm not exactly sure of the best way find the mugshot given the square coordinates of the face. 考虑到脸部的方形坐标,我不确定找到最佳方法的最佳方法。 Where can I find face to mugshot ratios? 我在哪里可以找到面对照片的比例?
    Edit : Solved this one. 编辑:解决了这个问题。 Assuming all my heads are ratios of their faces. 假设我的头都是他们脸的比例。

     static public Rectangle GetMugshotRectangle(Rectangle rFace) { int y2, x2, w2, h2; //adjust as neccessary double heightRatio = 2; y2 = Convert.ToInt32(rFace.Y - rFace.Height * (heightRatio - 1.0) / 2.0); h2 = Convert.ToInt32(rFace.Height * heightRatio); //height to width ratio is 1.25 : 1 in mugshots w2 = Convert.ToInt32(h2 * 4 / 5); x2 = Convert.ToInt32((rFace.X + rFace.Width / 2) - w2 / 2); return new Rectangle(x2, y2, w2, h2); } 

    桑德曼
    I just need to get rid of those false positives. 我只需要摆脱那些误报。

Ok make that 4 issues. 好吧,这4个问题。

  • Our camera that we will be using is currently out of commission so I don't have a method of capturing images at the moment. 我们将要使用的相机目前无法使用,因此我目前没有捕捉图像的方法。 Where can I find full body images of people that isn't pure pron like google's image search for full body images? 我在哪里可以找到像谷歌的图像搜索全身图像一样不是纯粹的人的全身图像?
    Edit : "Person standing" Makes a good search :) 编辑: “人站立”做了一个很好的搜索:)

A single cascade could do what all of your cascades do if it is set up this way, plus it does not give you several results to judge from. 如果以这种方式设置,单个级联可以执行你的所有级联所做的事情,而且它不会给你几个结果来判断。 The cascades you use are maybe different in the collection of teaching pictures they are made of or in some parameters. 您使用的级联在他们制作的教学图片集合或某些参数中可能不同。

A tutorial on how to build an own cascade can be found here . 可以在此处找到有关如何构建自己的级联的教程。 It would be useful to get the pictures used to train the four cascades you use but I don't know if they are publicly available. 获取用于训练您使用的四个级联的图片会很有用,但我不知道它们是否公开可用。

I suggest you to use Upper-body Haar cascade file which will return you the rectangle till shoulder. 我建议你使用上半身哈尔级联文件,它将返回矩形直到肩膀。 Please find Head and shoulders cascade file at " http://alereimondo.no-ip.org/OpenCV/34 " 请在“ http://alereimondo.no-ip.org/OpenCV/34 ”找到头肩级联文件

Ok, I figured it out but the project is on ice for the moment. 好吧,我想出来了,但目前这个项目还在冰上。
I do not have the source to paste as the VM takes forever to load up. 我没有要粘贴的源代码,因为VM需要永远加载。
If someone is really interested, let me know and I'll post. 如果有人真的感兴趣,请告诉我,我会发布。
If you see something that looks like it could be done better let me know. 如果你看到的东西看起来可以做得更好,请告诉我。

The steps I took were as follows. 我采取的步骤如下。

  1. Load the image, if greater than 500 pixels in either height or width make a new image of a version scaled down to a maximum of 500px height or width. 加载图像,如果高度或宽度大于500像素,则将新版本的图像缩小到最大500px高度或宽度。 Save the scale. 保存比例。
  2. Run the C# OpenCV implementation at Ask Ernest on all of the frontal face Harrcasscades at Harrtraining . Harrtraining的所有正面Harrcasscades上运行Ask Ernest的C#OpenCV实现。
  3. For some reason the rectangles produced by Ask Ernest need to be scaled up 1.3X 出于某种原因,Ask Ernest生产的矩形需要按比例放大1.3倍
  4. With the generated rectangles use standard deviation to remove false positives. 使用生成的矩形使用标准偏差来消除误报。 I did this for each corner of the rectangle finding the distance each rectangle corner was off from the average corner location. 我为矩形的每个角都做了这个,找到了每个矩形角离开平均角落位置的距离。 I made a note of any rectangle who had a corner out of whack and removed it from the list of candidate rectangles. 我记下了任何有一个角落的矩形,并将其从候选矩形列表中删除。
  5. Get the average rectangle from the remaining rectangles and apply "GetMugshotRectangle" from above in the question. 从剩余的矩形中获取平均矩形,并在问题中应用上面的“GetMugshotRectangle”。
  6. Scale the mugshot rectangle back up using the scale we saved in step 1. 使用我们在步骤1中保存的比例缩放杯子照片矩形。
  7. Cut out the mugshot from the original image and save to it's new location. 从原始图像中剪下照片并保存到新的位置。

Done! 完成!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM