opencv中的访问冲突写入位置

Posted

技术标签:

【中文标题】opencv中的访问冲突写入位置【英文标题】:access violation writing location in opencv 【发布时间】:2018-05-31 02:56:39 【问题描述】:

当代码到达这一行时,我在 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);

【问题讨论】:

哪个编译器?发布和调试构建?您的 OpenCV 二进制文件来自哪里? 你需要转义你的反斜杠。 ... 或者更好的是,使用正斜杠。 还是不行…… 为什么是 try/catch? Imread 不会抛出... 【参考方案1】:

OpenCV 3.3 是我自己在Ubuntu 16.04 上使用G++ 5.4 构建的。

此代码对我有用。 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);

【讨论】:

我完全复制了你的代码,但它不起作用(我插入了两个人 - 仍然有错误所以也许你错了)

以上是关于opencv中的访问冲突写入位置的主要内容,如果未能解决你的问题,请参考以下文章

C ++中的openCV Mat访问冲突

C++ + OpenCV = 访问冲突读取位置 0x02176000

opencv中split()函数运行出错

Mat OpenCV Rect ROI:访问冲突

还有一封信导致 imread 中的访问冲突

如何通过另一个具有位置(索引)的垫子访问opencv中的矩阵数据