2017-09-28 100 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

感謝您的幫助,但它仍然導致錯誤 –