2017-09-28 70 views
0

我在linux终端(C++在linux)中编译了以下代码,并使用OpenCv 3.3 在服务器以unsigned char *形式显示图片时,我将它转换为cv :: Mat如下:分割错误Opencv linux C++

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

然后我尝试2种方式从简历::垫的IplImage *,但在每种情况下转换,分割故障。

1路:

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路:

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

如果有人知道该如何解决?

回答

0

我认为你的Mat到Iplimage的转换是个问题。

我会尝试这样的事:

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

}

更多信息试试这个Converting cv::Mat to IplImage*

+0

感谢您的帮助,但它仍然导致错误 –