access violation writing location in opencv

泄露秘密 提交于 2020-01-13 07:24:04

问题


I get access violation writing location in face recognizer in opencv when the code getting to this line: model->train(images, labels);

the error: Unhandled exception at 0x00007FF9B494321B (opencv_core331.dll) in WHomeCamera.exe: 0xC0000005: Access violation writing location 0x0000000100000014. occurred

#include <opencv2\opencv.hpp>
#include <opencv2\highgui.hpp>
#include <opencv2\objdetect.hpp>
#include <opencv2\core.hpp>
#include <opencv2\face.hpp>
#include <opencv2\imgcodecs.hpp>
#include <iostream>
#include <string>

using namespace std;
using namespace cv;
using namespace face;

int main(void)
{
    vector <Mat> images; // vector of matrix for the images of the faces;
    vector <int> labels; // vector of int's for the labes (each person get      label ex: moshe - 0);

    try
    {
        images.push_back(imread("D:\imagesForProject\1.jpg",    CV_LOAD_IMAGE_GRAYSCALE)); // insert the face image;
        labels.push_back(0); // insert his label;

        images.push_back(imread("D:\imagesForProject\2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); // insert the face image;
        labels.push_back(0); // insert his label;

        images.push_back(imread("D:\imagesForProject\3.jpg", CV_LOAD_IMAGE_GRAYSCALE)); // insert the face image;
        labels.push_back(0); // insert his label;


    }

    catch(Exception& e)
    {
        cerr << "can't open the images" << e.msg << endl; // if we couldn't     open the files cerr it's basic cout for errors;
    }

    Ptr<FaceRecognizer> model = FisherFaceRecognizer::create();
    model->train(images, labels);
    return(0);
}

回答1:


OpenCV 3.3 built by myself using G++ 5.4 on Ubuntu 16.04.

This code works for me. Do not ask me why, you should find the difference by yourself.


#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/core.hpp>
#include <opencv2/face.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
#include <string>

using namespace std;
using namespace cv;
using namespace face;

int main(void)
{
    vector <Mat> images; // vector of matrix for the images of the faces;
    vector <int> labels; // vector of int's for the labes (each person get      label ex: moshe - 0);

    try{
        images.push_back(imread("Pictures/test0.png", CV_LOAD_IMAGE_GRAYSCALE)); // insert the face image;
        labels.push_back(0); // insert his label;
        images.push_back(imread("Pictures/test1.png", CV_LOAD_IMAGE_GRAYSCALE)); // insert the face image;
        labels.push_back(1); // insert his label;
    }catch(Exception& e){
        cerr << "can't open the images" << e.msg << endl; // if we couldn't     open the files cerr it's basic cout for errors;
    }

    Ptr<FaceRecognizer> model = FisherFaceRecognizer::create();
    model->train(images, labels);
    model->save("xxx.xml");
    return(0);
}


来源:https://stackoverflow.com/questions/47857057/access-violation-writing-location-in-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!