Opencv 如何最大限度地减少人脸检测误差

Opencv 如何最大限度地减少人脸检测误差,opencv,image-processing,processing,video-processing,face-detection,Opencv,Image Processing,Processing,Video Processing,Face Detection,下面是代码,我可以同时检测人脸和嘴巴,并且可以大致测量其边界框的距离有几个问题: 您不应该在draw()中每秒多次加载OpenCV级联。您应该在setup()中执行一次,然后在draw()中调用detect() OpenCV for Processing似乎用在第一个实例中加载的级联覆盖在第二个实例中加载的级联 如果准确度不是一个大问题,你可以通过一个简单的级联来解决:嘴级联。请注意,您可以使用检测功能的选项/提示来帮助检测。例如,你可以告诉检测器只检测最大的物体,给它一个提示,告诉它嘴在你的设

下面是代码,我可以同时检测人脸和嘴巴,并且可以大致测量其边界框的距离有几个问题:

  • 您不应该在
    draw()
    中每秒多次加载OpenCV级联。您应该在
    setup()
    中执行一次,然后在
    draw()中调用
    detect()
  • 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();
    }
    
    导入gab.opencv.*;
    导入java.awt.Rectangle;
    导入org.opencv.objdetect.objdetect;
    导入处理。视频。*;
    捕获视频;
    OpenCV-OpenCV;
    //级联检测参数-使用实际计算机视觉项目掌握OpenCV的说明
    int flags=Objdetect.CASCADE\u FIND\u max\u OBJECT;
    //最小对象大小。
    int minFeatureSize=20;
    int maxFeatureSize=80;
    //搜索应该有多详细。必须大于1.0。
    浮点搜索比例因子=1.1f;
    //应该过滤掉多少检测。这应该取决于错误检测对系统的影响程度。
    //minNeighbors=2表示有很多好的+坏的检测,minNeighbors=6表示给出了好的检测,但遗漏了一些。
    int-minNeighbors=6;
    无效设置(){
    尺寸(320240);
    noFill();
    冲程(0,192,0);
    冲程重量(3);
    视频=新捕获(此、宽度、高度);
    video.start();
    opencv=新的opencv(这是320240);
    opencv.loadCascade(opencv.CASCADE\u嘴);
    }
    作废提款(){
    //将cam图像馈送到OpenCV,它将其转换为灰度
    opencv.loadImage(视频);
    opencv.直方图();
    图像(opencv.getOutput(),0,0);
    矩形[]口=opencv.detect(searchScaleFactor、minNeighbors、flags、minFeatureSize、maxFeatureSize);
    for(int i=0;i
    请注意,面部毛发可能会导致误报。 我在一篇文章中提供了更深入的注释。我建议将重点放在FaceOSC部分,因为它会更准确

    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();
    }