【问题标题】:How to minimize face-detection error如何最小化人脸检测错误
【发布时间】:2016-09-02 23:07:34
【问题描述】:

这是现在我可以同时检测面部和嘴巴的代码,并且能够粗略测量其边界框的距离

问题是嘴巴检测似乎可以检测到他们定义为嘴巴的所有东西,即使不是

而且我想用“人脸”边界框作为嘴巴检测区域来尽量减少它的误差,不知道Forloop stacking是否可行?把嘴环放在脸环里面??我对编码还很陌生,任何帮助都将不胜感激

import gab.opencv.*;
import java.awt.Rectangle;
import processing.video.*;

Capture video;

OpenCV f;
OpenCV m;

void setup() {
size(800, 600);
video = new Capture(this, 800/2, 600/2);
f = new OpenCV(this, 800/2, 600/2);
m = new OpenCV(this, 800/2, 600/2);

video.start();
}

void draw() {
scale(2);
f.loadImage(video);
m.loadImage(video);
f.loadCascade(OpenCV.CASCADE_FRONTALFACE);
m.loadCascade(OpenCV.CASCADE_MOUTH);

image(video, 0, 0 );

noFill();
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] mouth = m.detect();
Rectangle[] face = f.detect();
println(mouth.length);

strokeWeight(3);
for (int i = 0; i < face.length; i++) {
println(face[i].x + "," + face[i].y);
rect(face[i].x, face[i].y, face[i].width, face[i].height);
}
for (int i = 0; i < mouth.length; i++) {
println(mouth[i].x + "," + mouth[i].y);
rect(mouth[i].x, mouth[i].y, mouth[i].width, mouth[i].height);
}

for (int i = 0; i < mouth.length; i++) {
fill(255, 0, 0);
noStroke();
ellipse((mouth[i].x)+(mouth[i].width/2), mouth[i].y, 5, 5);
ellipse((mouth[i].x)+(mouth[i].width/2), (mouth[i].y)+  (mouth[i].height), 5, 5);
}
for (int i = 0; i < mouth.length; i++) {
int px = (mouth[i].x)+(mouth[i].width/2);
int py = (mouth[i].y)+(mouth[i].height);
int mOpen = int (dist(px, mouth[i].y, px, py));
println(mOpen);
}
}
void captureEvent(Capture d) {
d.read();
}

【问题讨论】:

    标签: opencv image-processing processing video-processing face-detection


    【解决方案1】:

    有几个问题:

    1. 您不应该在draw() 中每秒多次加载 OpenCV 级联。您应该在setup() 中执行一次,然后在draw() 中调用detect()
    2. OpenCV for Processing 似乎用第一个实例中加载的级联覆盖了第二个实例中加载的级联

    如果准确性不是一个大问题,您可以使用一个级联:嘴一级。请注意,您可以将一些选项/提示用于检测功能,这可能有助于检测。例如,您可以告诉检测器只检测最大的物体,提示它在您的设置中嘴巴的最小和最大边界框以及应该过滤掉多少结果。

    这是上面的代码示例:

    import gab.opencv.*;
    import java.awt.Rectangle;
    import org.opencv.objdetect.Objdetect;
    import processing.video.*;
    
    Capture video;
    OpenCV opencv;
    
    //cascade detections parameters - explanations from Mastering OpenCV with Practical Computer Vision Projects
    int flags = Objdetect.CASCADE_FIND_BIGGEST_OBJECT;
    // Smallest object size.
    int minFeatureSize = 20;
    int maxFeatureSize = 80;
    // How detailed should the search be. Must be larger than 1.0.
    float searchScaleFactor = 1.1f;
    // How much the detections should be filtered out. This should depend on how bad false detections are to your system.
    // minNeighbors=2 means lots of good+bad detections, and minNeighbors=6 means good detections are given but some are missed.
    int minNeighbors = 6;
    
    void setup() {
      size(320, 240);
      noFill();
      stroke(0, 192, 0);
      strokeWeight(3);
    
      video = new Capture(this,width,height);
      video.start();
    
      opencv  = new OpenCV(this,320,240);
      opencv.loadCascade(OpenCV.CASCADE_MOUTH);
    }
    
    void draw() {
      //feed cam image to OpenCV, it turns it to grayscale
      opencv.loadImage(video);
      opencv.equalizeHistogram();
      image(opencv.getOutput(), 0, 0 );
    
      Rectangle[] mouths = opencv.detect(searchScaleFactor,minNeighbors,flags,minFeatureSize, maxFeatureSize);
      for (int i = 0; i < mouths.length; i++) {
        text(mouths[i].x + "," + mouths[i].y + "," + mouths[i].width + "," + mouths[i].height,mouths[i].x, mouths[i].y);
        rect(mouths[i].x, mouths[i].y, mouths[i].width, mouths[i].height);
      }
    }
    void captureEvent(Capture c) {
      c.read();
    }
    

    请注意,面部毛发可能会导致误报。 我在answer to your previous related question 中提供了更深入的注释。我建议专注于 FaceOSC 部分,因为它会更准确。

    【讨论】:

      猜你喜欢
      • 2012-08-27
      • 2014-12-01
      • 2021-01-12
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 2017-01-18
      相关资源
      最近更新 更多