在opencv中访问违规写入位置

问题描述 投票:-1回答:1

当代码到达此行时,我在opencv中的面部识别器中获得访问冲突写入位置:model-> train(images,labels);

错误:WHOMECamera.exe中0x00007FF9B494321B(opencv_core331.dll)的未处理异常:0xC0000005:访问冲突写入位置0x0000000100000014。发生了

#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);
}
c++ opencv face-recognition
1个回答
0
投票

OpenCV 3.3由我自己在G++ 5.4上使用Ubuntu 16.04建造。

这段代码适合我。 Do not ask me why,你should找到差异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);
}
© www.soinside.com 2019 - 2024. All rights reserved.