访问冲突异常抛出OpenCV

时间:2017-06-27 00:03:29

标签: c++ opencv exception opencv3.0 opencv3.2

我正在使用带有OpenCV 3.2.0和haarcascades的Visual Studio 2017进行简单的人脸检测。 每当我运行这个,我得到一个错误,说我创建第一个点后立即抛出异常。访问冲突错误。任何帮助将不胜感激,因为我没有在代码中看到任何错误。 Here is a picture of the exception thrown.

#include <opencv2/opencv.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
#include <vector>



using namespace std;
using namespace cv; 

int main()
{
    CascadeClassifier face_cascade;
    CascadeClassifier eye_cascade;
    face_cascade.load("haarcascade_frontalface_alt.xml");
    eye_cascade.load("haarcascade_eye_tree_eyeglasses.xml");
    VideoCapture cap(0);
    Mat frame;
    while (cap.read(frame))
    {
        Mat frame_gray;
        std::vector <Rect> faces;
        cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
        equalizeHist(frame_gray, frame_gray);
        face_cascade.detectMultiScale(frame_gray,faces, 1.1, 2,0,Size(30,30),Size(300,300));
        for (size_t i = 0; i < faces.size();i++)
        {


            Point first(faces[i].x, faces[i].y);
            Point second(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
            rectangle(frame,second,first, cvScalar(255, 0, 0), 1, 8, 0);

        }

        imshow("Test", frame_gray);
        waitKey(30);
    }
    return 0;
}

0 个答案:

没有答案