如何最大限度地减少面部检测错误

时间:2016-05-08 05:55:11

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

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

问题是口腔检测似乎检测到他们定义为口腔的所有东西,即使它不是

我想使用" face"边界框作为口腔检测区域,以尽量减少其误差,我不知道Forloop堆叠是否有效?把口环放在脸部环路里?我很乐意编写任何帮助,我们将不胜感激

   <?php
    $dbh = "localhost";
    $dbn = "dbname";
    $dbu = "dbuser";
    $dbp = "dbpassword";

    $conn = mysql_connect($dbh,$dbu,$dbp) or die("Unable to connect do database.");
    mysql_select_db($dbn, $conn) or die("Unable to select database."); 

    $result = mysql_query("SHOW TABLES FROM $dbn") or die("Cannot list table names.");
    echo "
    <form name=\"table_browser\" action=\"".$PHP_SELF."\" method=\"GET\" >
        <select name=\"t\" onChange=\"javascript:submit();\">
            <option>Select a table</option>
    ";
    while ($row = mysql_fetch_row($result)){
        echo "        <option value=".$row[0].">".$row[0]."</option>\n";
    }
    echo "    </select>
    </form>\n";

    if (!isset($t)){
        die("Please select a table");
    }
    ?>

1 个答案:

答案 0 :(得分:1)

有几个问题:

  1. 您不应该在draw()中每秒多次加载OpenCV级联。您应该在setup()中执行一次,然后在detect()
  2. 中致电draw()
  3. OpenCV for Processing似乎覆盖第二个实例中加载的级联,并在第一个实例中加载了级联
  4. 如果准确性不是一个大问题,那么你可以通过一个级联来实现:一个级联。请注意,您可以使用检测功能的选项/提示,这可能有助于检测。例如,你可以告诉探测器只检测最大的物体,给它一个最小和最大的边界框的提示,这些边界框可能与你的设置有关,以及滤除结果的数量。

    以下是上述代码示例:

    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部分,因为它会更准确。