如何获得“照片”来自人脸检测方块?

发布于 2024-11-02 12:16:52 字数 1660 浏览 0 评论 0原文

我正在构建一个应用程序,它将拍摄一个人的全身图像,并为该人生成一个“照片”。

面部照片是指该人的整个脸部、颈部、头发和耳朵的图像,其大小与另一张面部照片相同。

目前我正在使用
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. SandmanWayne
    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);
    }
    

    Sandman
    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

a√萤火虫的光℡ 2024-11-09 12:16:52

如果以这种方式设置,单个级联可以完成所有级联所做的事情,而且它不会提供多个结果供您判断。您使用的级联可能在组成教学图片的集合或某些参数上有所不同。

有关如何构建自己的级联的教程可以在此处找到。获取用于训练您使用的四个级联的图片会很有用,但我不知道它们是否是公开的。

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.

ぶ宁プ宁ぶ 2024-11-09 12:16:52

如果您在 2020 年代阅读这个问题,那么已经开发出更新的解决方案来简化此任务。可能值得一看的库包括

来解决照片问题使用 FaceAiSharp 的任务,您可以使用与此类似的代码:

  1. dotnet new console

  2. dotnet 添加包 FaceAiSharp.Bundle
    dotnet 添加包 Microsoft.ML.OnnxRuntime
    
  3. 编辑Program.cs

using FaceAiSharp;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

// adjust these lines to load your own image
using var hc = new HttpClient();
var groupPhoto = await hc.GetByteArrayAsync(
    "https://upload.wikimedia.org/wikipedia/commons/1/1e/1942_JFK_uniform_portrait.jpg");
var img = Image.Load<Rgb24>(groupPhoto);

var det = FaceAiSharpBundleFactory.CreateFaceDetector();
FaceAiSharp.Applications.CropProfilePicture(det, img, scaleFactor: 1.5f);
img.Save("mugshot.jpg");
  1. 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

To solve the mugshot task using FaceAiSharp you could use code similar to this:

  1. dotnet new console

  2. dotnet add package FaceAiSharp.Bundle
    dotnet add package Microsoft.ML.OnnxRuntime
    
  3. Edit Program.cs:

using FaceAiSharp;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

// adjust these lines to load your own image
using var hc = new HttpClient();
var groupPhoto = await hc.GetByteArrayAsync(
    "https://upload.wikimedia.org/wikipedia/commons/1/1e/1942_JFK_uniform_portrait.jpg");
var img = Image.Load<Rgb24>(groupPhoto);

var det = FaceAiSharpBundleFactory.CreateFaceDetector();
FaceAiSharp.Applications.CropProfilePicture(det, img, scaleFactor: 1.5f);
img.Save("mugshot.jpg");
  1. 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.

深府石板幽径 2024-11-09 12:16:52

好吧,我明白了,但该项目目前处于冻结状态。
我没有可以粘贴的源代码,因为虚拟机需要很长时间才能加载。
如果有人真的感兴趣,请告诉我,我会发帖。
如果您发现一些看起来可以做得更好的事情,请告诉我。

我采取的步骤如下。

  1. 加载图像,如果高度或宽度大于 500 像素,则将版本的新图像缩小到最大 500 像素高度或宽度。保存秤。
  2. 询问 Ernest 上运行 C# OpenCV 实现所有正面 Harrcascades 位于 骚扰训练
  3. 由于某种原因,Ask Ernest 生成的矩形需要放大 1.3 倍
  4. ,生成的矩形使用标准差 消除误报。我对矩形的每个角执行此操作,找到每个矩形角与平均角位置的距离。我记下了任何一个角不正常的矩形,并将其从候选矩形列表中删除。
  5. 从剩余的矩形中获取平均矩形,并在问题中应用上面的“GetMugshotRectangle”。
  6. 使用我们在步骤 1 中保存的比例缩放照片矩形。
  7. 从原始图像中剪切照片并保存到新位置。

完毕!

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.

  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. Save the scale.
  2. Run the C# OpenCV implementation at Ask Ernest on all of the frontal face Harrcasscades at Harrtraining.
  3. For some reason the rectangles produced by Ask Ernest need to be scaled up 1.3X
  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.
  6. Scale the mugshot rectangle back up using the scale we saved in step 1.
  7. Cut out the mugshot from the original image and save to it's new location.

Done!

所谓喜欢 2024-11-09 12:16:52

我建议您使用上半身 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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文