【问题标题】:OpenCv and Visual C++ Face detectionOpenCv 和 Visual C++ 人脸检测
【发布时间】:2017-12-24 02:18:59
【问题描述】:

我目前正在尝试编写一个人脸检测程序,即使它能够成功构建,我似乎也遇到了一些小问题。关于如何解决这个问题的任何想法?下面表示我调试时出现的错误和我的代码。

检测.cpp:

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;


int main(int argc, char** argv)
{
    // capture from web camera init

    VideoCapture cap(0);
    cap.open(0);

    Mat img;

    // Initialize the inbuilt Harr Cascade frontal face detection
    // Below mention the path of where your haarcascade_frontalface_alt2.xml file is located

    CascadeClassifier face_cascade;
    face_cascade.load("C:\OpenCV\sources\data\haarcascades\haarcascade_frontalface_alt2.xml");    
    // i tried changing this line to match my folder in C Drive

    for (;;)
    {

        // Image from camera to Mat

        cap >> img;

        // obtain input image from source
        cap.retrieve(img, CV_CAP_OPENNI_BGR_IMAGE);

        // Just resize input image if you want
        resize(img, img, Size(1000, 640));

        // Container of faces
        vector<Rect> faces;


        // Detect faces
        face_cascade.detectMultiScale(img, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(140, 140));
        // error message appears here


        //Show the results
        // Draw circles on the detected faces

        for (int i = 0; i < faces.size(); i++)
        {
            Point center(faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5);
            ellipse(img, center, Size(faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
        }

        // To draw rectangles around detected faces
        /* for (unsigned i = 0; i<faces.size(); i++)
        rectangle(img,faces[i], Scalar(255, 0, 0), 2, 1);*/


        imshow("wooohooo", img);
        int key2 = waitKey(20);

    }
    return 0;
}

错误信息:

Unhandled exception at 0x000007FEFD5CA06D in opencvTry.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000029EE10. occurred

【问题讨论】:

  • 抛出的异常有调用栈——检查你的调试器。该调用堆栈上你的代码的最后一行是什么?
  • 显然这只是我在链接语句中犯的一个简单错误。解决了

标签: c++ visual-studio-2017 opencv3.2


【解决方案1】:

在我一一查看我的代码后,我意识到它只是导致错误的反斜杠。我在上面使用的代码是这样的:

face_cascade.load("C:\OpenCV\sources\data\haarcascades\haarcascade_frontalface_alt2.xml");    

但实际上应该是这样的:

face_cascade.load("C:/OpenCV/sources/data/haarcascades/haarcascade_frontalface_alt2.xml");

【讨论】:

    猜你喜欢
    • 2014-01-31
    • 2017-07-19
    • 2012-02-04
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 2012-04-15
    相关资源
    最近更新 更多