2016-05-29 189 views
0

this example我試着用下面的值來初始化一個OpenCV的Mat初始化CV ::墊與數據不起作用

cv::Mat image = (cv::Mat_<int>(3,3) << 0, 255, 0, 0, 255, 0, 0, 255, 0); 

然而,我的IDE與

Binary operator '<<' can't be applied to the expressions of type 'cv::Mat_<int>' and 'int' 

和抱怨時編譯我得到

OpenCV Error: The function/feature is not implemented (Unsupported combination of source format (=4), and buffer format (=5)) in getLinearRowFilter, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/filter.cpp, line 2857 
terminate called after throwing an instance of 'cv::Exception' 
    what(): /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/filter.cpp:2857: error: (-213) Unsupported combination of source format (=4), and buffer format (=5) in function getLinearRowFilter 

我用Python的openCV相當雖然現在,但我完全失去了在C++中使用它。

+0

錯誤與您發佈的代碼無關。請發佈相關代碼。 – Berriel

回答

1

您可能試圖應用使用getLinearRowFilter()(如Sobel等)的函數(或過濾器),並且您正在使用不允許的類型(輸入和輸出)的組合。

您可以檢查所允許的組合here,其中sdepth是源(input)和ddepth的深度目的地的深度(output):

// these are allowed, otherwise the error will be thrown 
if(sdepth == CV_8U && ddepth == CV_32S) 
if(sdepth == CV_8U && ddepth == CV_32F) 
if(sdepth == CV_8U && ddepth == CV_64F) 
if(sdepth == CV_16U && ddepth == CV_32F) 
if(sdepth == CV_16U && ddepth == CV_64F) 
if(sdepth == CV_16S && ddepth == CV_32F) 
if(sdepth == CV_16S && ddepth == CV_64F) 
if(sdepth == CV_32F && ddepth == CV_32F) 
if(sdepth == CV_32F && ddepth == CV_64F) 
if(sdepth == CV_64F && ddepth == CV_64F) 

基礎上的錯誤,你可能使用CV_32S=4)輸入和CV_32F=5)輸出。基本上,您不能使用CV_32S(a Mat_<int>)作爲使用getLinearRowFilter()的函數的輸入。

要解決這個問題,您可以在使用它之前轉換輸入。例如:

cv::Mat1i image = ...; // suppose this is your input (CV_32S == Mat_<int>) 
cv::Mat1f output = ...; // suppose this is your output (CV_32F == Mat_<float>) 

image.convertTo(image, CV_32F); // add this line right before the call 
call_to_filter(image, output, ...); // your function (or filter) call 
// e.g.: cv::Sobel(image, output, ...) will throw this error without convertion 

注意:信息不準確,因爲並非所有相關代碼都在問題中。