2014-02-22 132 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

相关问题