简体   繁体   中英

Segmentation Fault Opencv linux c++

I have the following code compiled in linux terminal (c++ in linux) and am using OpenCv 3.3 On the server comes in picture in the form of unsigned char *, I convert it to cv::Mat as follows:

Mat charToMat(unsigned char * bytes, int width, int height){
    return Mat(height, width, CV_8UC3, bytes);
}

Then I tried 2 ways to convert from cv::Mat to IplImage *, but in each case, the Segmentation Fault occurs.

1 way:

int * ft(Mat ft, int width, int height, int countA4) {
        sourceImg = cvCreateImage(cvSize(ft.cols, ft.rows), 8, 3);
        IplImage im = ft; 
        cvCopy(&im, sourceImg); // Segmentation Fault
}

2 way:

int * ft (Mat ft, int width, int height, int countA4) {
        IplImage im = ft;
        sourceImg = cvCloneImage(&im);// Segmentation Fault
}

If anybody knows the solution?

I think that your conversion of Mat to Iplimage is the problem.

I would try something like this:

int * ft (Mat ft, int width, int height, int countA4) {
    IplImage* img = new IplImage(ft);
    sourceImg = cvCloneImage(im);

}

for more info try this Converting cv::Mat to IplImage*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM