2014-02-22 130 views
1

我transfering matlab代碼到C++使用OpenCv2.2,在函數(CONV2),其被製造成類似的matlab一個,我使用filter2D即來自OpenCv2.2 C++ filter2D

#include <opencv2/imgproc/imgproc.hpp> 

的問題是,我得到的錯誤信息:

OpenCV Error: The function/feature is not implemented (Unsupported combination of source format (=4), and destination format (=4)) in getLinearFilter, file C:\opencv\sources\modules\imgproc\src\filter.cpp, line 3234

terminate called after throwing an instance of 'cv::Exception'

what(): C:\opencv\sources\modules\imgproc\src\filter.cpp:3234: error: (-213) Unsupported combination of source format (=4), and destination format (=4) in function getLinearFilter

這是我第一次看到這樣的錯誤之一。所以,我不會真正知道這是來自我的instal還是來自代碼。

==============================================附件:

代碼:

void conv2(const Mat &img, const Mat& kernel, ConvolutionType type, Mat& dest) 
{ 
    // fonction trouvée sur le site : 
    // http://blog.timmlinder.com/2011/07/opencv-equivalent-to-matlabs-conv2-function/ 
    // par Timm Linder le 05/07/2011 
    Mat source = img; 
    if(CONVOLUTION_FULL == type) { 
    source = Mat(); 
    const int additionalRows = kernel.rows-1, additionalCols = kernel.cols-1; 
    copyMakeBorder(img, source, (additionalRows+1)/2, additionalRows/2, (additionalCols+1)/2, additionalCols/2, BORDER_CONSTANT, Scalar(0)); 
    } 

    Point anchor(kernel.cols - kernel.cols/2 - 1, kernel.rows - kernel.rows/2 - 1); 
    int borderMode = BORDER_CONSTANT; 

    filter2D(source, dest, img.depth(), flip(kernel), anchor, 0, borderMode); 

    //cvFilter2D(source, dest, img.depth(), flip(kernel), anchor, 0, borderMode); 

    if(CONVOLUTION_VALID == type) { 
    dest = dest.colRange((kernel.cols-1)/2, dest.cols - kernel.cols/2) 
       .rowRange((kernel.rows-1)/2, dest.rows - kernel.rows/2); 
    } 
} 

在這個博客上找到: http://blog.timmlinder.com/2011/07/opencv-equivalent-to-matlabs-conv2-function/ (如果有人有bether IDEAR重現可能被intresting的CONV 2)

回答

1

filter2d docs, - 它很明顯你不能使用int32 Mats(type()== 4)。

你就必須轉換爲CV_8U,CV_16U,CV_32F之一,CV_64F

(也考慮更新OpenCV的2.2是很老)

+0

謝謝你的快速響應, 我改變我的Mat從CV_32S到CV_32F的格式和錯誤消失了。 (因爲我很安靜遠離我的領域,我發現在博客文章下的評論是受歡迎的) 但仍然謝謝你的答案。 – user1581475

相關問題