OpenCv2.2 C++ filter2D
c++, matlab, opencv
Solution
looking at the filter2d docs , - it's obvious that you can't work with int32 Mats (type()==4).
you'll have to convert to one of CV_8U,CV_16U,CV_32F,CV_64F
(also consider updating your opencv. 2.2 is quite old)
Problem
I'm transfering matlab code to c++ using OpenCv2.2, In a function (conv2) that is made to be similar to the matlab one, I use filter2D that comes from ``` #include <opencv2/imgproc/imgproc.hpp> ``` the problem is the error message that I get : 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 It's the first time that i see an error like this one. So, i don't realy know if this comes from my instal or from the code. ============================================================================================ Annexe : Code : ``` 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); } } ``` found on this blog : http://blog.timmlinder.com/2011/07/opencv-equivalent-to-matlabs-conv2-function/ (If some one have bether idear to reproduce the conv2 that could be intresting)