0

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?

1 Answers1

0

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*

vnuke
  • 1
  • 1
  • 1