使用OpenCV3的视频中的人脸识别会产生未处理的异常(opencv_core310.dll) [英] Face Recognition in Videos with OpenCV3 gives Unhandled exception (opencv_core310.dll)

查看:98
本文介绍了使用OpenCV3的视频中的人脸识别会产生未处理的异常(opencv_core310.dll)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码用来识别我从下面的链接获得的脸

Below code used to recognize face which i got from the below link

http://docs.opencv .org/3.0-beta/modules/face/doc/facerec/tutorial/facerec_video_recognition.html .

我所做的唯一修改是:我没有使用命令行参数来提供CSV和Cascade分类器路径,而是直接在代码中给了它们.

The only modification I've done is: Instead of using command line arguments to provide CSV and Cascade classifier paths, I have given them directly in the code.

问题 在facerecognization.exe中的0x00007FFDD0C0E09B(opencv_core310.dll)处引发异常:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF.

Problem Exception thrown at 0x00007FFDD0C0E09B (opencv_core310.dll) in facerecognization.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

我遇到如图所示的访问冲突问题.

i am getting access violation problem as shown .

为解决我试图解决的问题

1)逐步调试,代码到达此行时出现异常 CascadeClassifier haar_cascade;在model-> train

1)to debug step by step i get the exception when code reaches this line CascadeClassifier haar_cascade; after model->train

2)我重新安装了两次所有内容,即opencv_contru,但再次出现相同的问题

2)i reinstalled twice everything ie opencv_contru but again i same problem

3)我最初使用at& t数据库作为at.txt,并且由于它使用.pgm文件(Windows无法识别并且当我遇到相同问题时),所以我使用.jpg创建了自己的数据库,即facecsv.txt(我的数据库有10套),但同样的问题仍然存在

3) i initially used at&t database as at.txt and since it use .pgm file (windows doesnt recognize and when i ran same problem),so i created my own data base with .jpg ie facecsv.txt(my database with 10 sets) but same problem persist

4)我将haarcascade_frontalface_default.xml更改为其他.xml文件,但仍然存在相同的问题

4) i changed haarcascade_frontalface_default.xml to other .xml files but still the same problem

5)dll两次配置都没有问题

5)dll is not a problem as configured it twice

代码

#include "opencv2/core.hpp"
#include "opencv2/face.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect.hpp"

#include <iostream>
#include <fstream>
#include <sstream>

using namespace cv;
using namespace cv::face;
using namespace std;
int abc;


static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';') {
    std::ifstream file(filename.c_str(), ifstream::in);
    if (!file) {
        string error_message = "No valid input file was given, please check the given filename.";
        CV_Error(CV_StsBadArg, error_message);
    }
    string line, path, classlabel;
    while (getline(file, line)) {
        stringstream liness(line);
        getline(liness, path, separator);
        getline(liness, classlabel);
        if (!path.empty() && !classlabel.empty()) {
            images.push_back(imread(path, 0));
            labels.push_back(atoi(classlabel.c_str()));
        }
    }
}

int main(int argc, const char *argv[]) {

    // Get the path to your CSV:
    string fn_haar = "C:\\OpenCV-3.1.0\\opencv\\build2\\install\\etc\\haarcascades\\haarcascade_frontalface_default.xml";
    string fn_csv = "C:\\OpenCV-3.1.0\\facedata\\facecsv.txt";
    int deviceId = 0;
    // These vectors hold the images and corresponding labels:
    vector<Mat> images;
    vector<int> labels;
    // Read in the data (fails if no valid input filename is given, but you'll get an error message):
    try {
        read_csv(fn_csv, images, labels);
    }
    catch (cv::Exception& e) {
        cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
        // nothing more we can do

        cin >> abc;
        exit(1);
    }
    // Get the height from the first image. We'll need this
    // later in code to reshape the images to their original
    // size AND we need to reshape incoming faces to this size:
    int im_width = images[0].cols;
    int im_height = images[0].rows;
    // Create a FaceRecognizer and train it on the given images:
    Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
    model->train(images, labels);
    // That's it for learning the Face Recognition model. You now
    // need to create the classifier for the task of Face Detection.
    // We are going to use the haar cascade you have specified in the
    // command line arguments:
    //
    CascadeClassifier haar_cascade;
    haar_cascade.load(fn_haar);
    // Get a handle to the Video device:
    VideoCapture cap(deviceId);
    // Check if we can use this device at all:
    if (!cap.isOpened()) {
        cerr << "Capture Device ID " << deviceId << "cannot be opened." << endl;
        return -1;
    }
    // Holds the current frame from the Video device:
    Mat frame;
    for (;;) {
        cap >> frame;
        // Clone the current frame:
        Mat original = frame.clone();
        // Convert the current frame to grayscale:
        Mat gray;
        cvtColor(original, gray, CV_BGR2GRAY);
        // Find the faces in the frame:
        vector< Rect_<int> > faces;
        haar_cascade.detectMultiScale(gray, faces);
        // At this point you have the position of the faces in
        // faces. Now we'll get the faces, make a prediction and
        // annotate it in the video. Cool or what?
        for (int i = 0; i < faces.size(); i++) {
            // Process face by face:
            Rect face_i = faces[i];
            // Crop the face from the image. So simple with OpenCV C++:
            Mat face = gray(face_i);
            // Resizing the face is necessary for Eigenfaces and Fisherfaces. You can easily
            // verify this, by reading through the face recognition tutorial coming with OpenCV.
            // Resizing IS NOT NEEDED for Local Binary Patterns Histograms, so preparing the
            // input data really depends on the algorithm used.
            //
            // I strongly encourage you to play around with the algorithms. See which work best
            // in your scenario, LBPH should always be a contender for robust face recognition.
            //
            // Since I am showing the Fisherfaces algorithm here, I also show how to resize the
            // face you have just found:
            Mat face_resized;
            cv::resize(face, face_resized, Size(im_width, im_height), 1.0, 1.0, INTER_CUBIC);
            // Now perform the prediction, see how easy that is:
            int prediction = model->predict(face_resized);
            // And finally write all we've found out to the original image!
            // First of all draw a green rectangle around the detected face:
            rectangle(original, face_i, CV_RGB(0, 255, 0), 1);
            // Create the text we will annotate the box with:
            string box_text = format("Prediction = %d", prediction);
            // Calculate the position for annotated text (make sure we don't
            // put illegal values in there):
            int pos_x = std::max(face_i.tl().x - 10, 0);
            int pos_y = std::max(face_i.tl().y - 10, 0);
            // And now put it into the image:
            putText(original, box_text, Point(pos_x, pos_y), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0, 255, 0), 2.0);
        }
        // Show the result:
        imshow("face_recognizer", original);
        // And display it:
        char key = (char)waitKey(20);
        // Exit this loop on escape:
        if (key == 27)
            break;
    }
    return 0;
}

我的数据库看起来像 facecsv.txt

C:\OpenCV-3.1.0\facedata\Angelina Jolie/Angelina_1.jpg;0
C:\OpenCV-3.1.0\facedata\Angelina Jolie/Angelina_2.jpg;0
C:\OpenCV-3.1.0\facedata\Angelina Jolie/angelina_3.jpg;0
C:\OpenCV-3.1.0\facedata\Arnold Schwarzenegger/Arnold_1.jpg;1
C:\OpenCV-3.1.0\facedata\Arnold Schwarzenegger/Arnold_2.jpg;1
C:\OpenCV-3.1.0\facedata\Arnold Schwarzenegger/Arnold_3.jpg;1
C:\OpenCV-3.1.0\facedata\Brad Pitt/Brad_1.jpg;2
C:\OpenCV-3.1.0\facedata\Brad Pitt/Brad_2.jpg;2
C:\OpenCV-3.1.0\facedata\Brad Pitt/Brad_3.jpg;2
C:\OpenCV-3.1.0\facedata\Emma Watson/Emma_1.jpg;3
C:\OpenCV-3.1.0\facedata\Emma Watson/Emma_2.jpg;3
C:\OpenCV-3.1.0\facedata\Emma Watson/Emma_3.jpg;3
C:\OpenCV-3.1.0\facedata\Justin Timberlake/Justin_1.jpg;4
C:\OpenCV-3.1.0\facedata\Justin Timberlake/Justin_2.jpg;4
C:\OpenCV-3.1.0\facedata\Justin Timberlake/Justin_3.jpg;4
C:\OpenCV-3.1.0\facedata\Katy Perry/Katy_1.jpg;5
C:\OpenCV-3.1.0\facedata\Katy Perry/Katy_2.jpg;5
C:\OpenCV-3.1.0\facedata\Katy Perry/Katy_3.jpg;5
C:\OpenCV-3.1.0\facedata\Keanu Reeves/Keanu_1.jpg;6
C:\OpenCV-3.1.0\facedata\Keanu Reeves/Keanu_2.jpg;6
C:\OpenCV-3.1.0\facedata\Keanu Reeves/Keanu_3.jpg;6
C:\OpenCV-3.1.0\facedata\Nisarg/Nisarg_1.jpg;7
C:\OpenCV-3.1.0\facedata\Nisarg/Nisarg_2.jpg;7
C:\OpenCV-3.1.0\facedata\Nisarg/Nisarg_3.jpg;7
C:\OpenCV-3.1.0\facedata\Nisarg/Nisarg_4.jpg;7
C:\OpenCV-3.1.0\facedata\Nisarg/Nisarg_5.jpg;7
C:\OpenCV-3.1.0\facedata\Tom Cruise/Tom_1.jpg;8
C:\OpenCV-3.1.0\facedata\Tom Cruise/Tom_2.jpg;8
C:\OpenCV-3.1.0\facedata\Tom Cruise/Tom_3.jpg;8

和at& t数据库

C:\OpenCV-3.1.0\att_faces (1)\database\s1/1.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/10.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/2.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/3.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/4.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/5.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/6.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/7.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/8.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s1/9.pgm;0
C:\OpenCV-3.1.0\att_faces (1)\database\s10/1.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/10.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/2.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/3.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/4.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/5.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/6.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/7.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/8.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s10/9.pgm;1
C:\OpenCV-3.1.0\att_faces (1)\database\s11/1.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/10.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/2.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/3.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/4.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/5.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/6.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/7.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/8.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s11/9.pgm;2
C:\OpenCV-3.1.0\att_faces (1)\database\s12/1.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/10.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/2.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/3.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/4.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/5.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/6.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/7.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/8.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s12/9.pgm;3
C:\OpenCV-3.1.0\att_faces (1)\database\s13/1.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/10.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/2.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/3.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/4.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/5.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/6.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/7.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/8.pgm;4
C:\OpenCV-3.1.0\att_faces (1)\database\s13/9.pgm;4
and it goes upto 40 test sample s1 to s40

问题

Exception thrown at 0x00007FFDD0C0E09B (opencv_core310.dll) in facerecognization.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

我正在将Windows 10 64位与Visual Studio 2015和OpenCV 3.1.0以及opencv_contrib-master(构建配置:x64-Debug)一起使用

I am using Windows 10 64-bit with Visual Studio 2015 and OpenCV 3.1.0 and opencv_contrib-master (Build Configuration: x64-Debug)

这里的问题类似使用OpenCV进行视频中的人脸识别给出未处理的异常 但他只使用了1个标签,但我使用了8个以上,但并没有解决我的问题

Their is similar question here Face Recognition in Video using OpenCV gives unhandled exception but he used only one 1 label but i use more than 8 that didn't solved my problem

推荐答案

我正在将Windows 10 64位与Visual Studio 2015和OpenCV 3.1.0以及opencv_contrib-master(构建配置:x64- Debug ")配合使用

您正在链接到版本库,但是您处于调试模式.

You're linking to release libraries, but you're in debug mode.

debug 中,您需要使用尾随的"d"链接到OpenCV库:opencv_<module><version>d.lib.

In debug you need to link to OpenCV libraries with the trailing "d": opencv_<module><version>d.lib.

因此,您的情况是:opencv_core310d.lib等...

So in your case to: opencv_core310d.lib, etc...

这篇关于使用OpenCV3的视频中的人脸识别会产生未处理的异常(opencv_core310.dll)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆