如何获得“照片”来自人脸检测方块?
我正在构建一个应用程序,它将拍摄一个人的全身图像,并为该人生成一个“照片”。
面部照片是指该人的整个脸部、颈部、头发和耳朵的图像,其大小与另一张面部照片相同。
目前我正在使用
http://askernest.com/archive/2008/05 /03/人脸检测-in-c.aspx
实现 OpenCV 并用作
harrcascade_frontalface_default.xml
harrcascade_frontalface_alt.xml
harrcascade_frontalface_alt2.xml
harrcascade_frontalface_alt_tree.xml
我的级联。
我使用所有级联,因为单个级联无法检测到我所有的面孔。当我得到所有级联检测到的所有面孔后,我找到了我的平均平方,并用它来最终猜测照片的高度和宽度。
我的问题是 3 个部分。
我目前的进程相当缓慢。如何加快检测过程?
编辑:我发现处理时间与照片尺寸直接相关。减小照片的大小可能会有所帮助。单个级联无法检测到我遇到的所有面孔,因此我正在使用所有面孔。这当然会产生许多不同的方块和一些误报。我可以使用什么方法来识别误报并将其排除在平均平方计算之外?前任。
编辑:我正在实现标准差内的平均值。很快就会发布代码。我不太确定在给定面部坐标的情况下找到照片的最佳方法。在哪里可以找到面部照片比例?
编辑:解决了这个问题。假设我所有的头都是他们脸的比例。静态公共矩形 GetMugshotRectangle(矩形 rFace) { int y2、x2、w2、h2; //根据需要调整 双倍高度比 = 2; y2 = Convert.ToInt32(rFace.Y - rFace.Height * (heightRatio - 1.0) / 2.0); h2 = Convert.ToInt32(rFace.Height * heightRatio); //照片中的高宽比为 1.25 : 1 w2 = Convert.ToInt32(h2 * 4 / 5); x2 = Convert.ToInt32((rFace.X + rFace.Width / 2) - w2 / 2); 返回新的矩形(x2,y2,w2,h2); }
我只需要消除这些误报。
好吧,这是 4 个问题。
我们将使用的相机目前无法使用,因此我目前没有捕获图像的方法。我在哪里可以找到不纯粹的人的全身图像,例如谷歌的全身图像图像搜索?
编辑:“站立的人”进行了很好的搜索:)
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.
Currently I'm using
http://askernest.com/archive/2008/05/03/face-detection-in-c.aspx
to implement OpenCV and I'm using
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.
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.
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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果以这种方式设置,单个级联可以完成所有级联所做的事情,而且它不会提供多个结果供您判断。您使用的级联可能在组成教学图片的集合或某些参数上有所不同。
有关如何构建自己的级联的教程可以在此处找到。获取用于训练您使用的四个级联的图片会很有用,但我不知道它们是否是公开的。
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.
如果您在 2020 年代阅读这个问题,那么已经开发出更新的解决方案来简化此任务。可能值得一看的库包括
System.Drawing
并包含作者提供的模型来解决照片问题使用 FaceAiSharp 的任务,您可以使用与此类似的代码:
dotnet new console
编辑
Program.cs
:dotnet run
尝试不同的
scaleFactor
值来扩大或缩小裁剪范围。免责声明:我是 FaceAiSharp 的作者。它是麻省理工学院许可的。如果某些内容不适合您或可能会出现问题,请随时提出问题改善了。
If you're reading this question in the 2020s, more recent solutions have been developed that simplify this task. Libraries that might be worth taking a look at include
System.Drawing
and includes models provided by the authorTo solve the mugshot task using FaceAiSharp you could use code similar to this:
dotnet new console
Edit
Program.cs
:dotnet run
Try different
scaleFactor
values to widen or narrow the crop.Disclaimer: I'm the author of FaceAiSharp. It's MIT-licensed. Don't hesitate to open an issue if something doesn't work for you or could be improved.
好吧,我明白了,但该项目目前处于冻结状态。
我没有可以粘贴的源代码,因为虚拟机需要很长时间才能加载。
如果有人真的感兴趣,请告诉我,我会发帖。
如果您发现一些看起来可以做得更好的事情,请告诉我。
我采取的步骤如下。
完毕!
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.
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.
Done!
我建议您使用上半身 Haar 级联文件,它将返回到肩部的矩形。
请在“http://alereimondo.no-ip.org/OpenCV/ 找到头肩级联文件34 "
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"