Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

filter2d vs conv2

The result I get from conversion of conv2 function in matlab is very different from the result I get in opencv using filter2d function. In opencv in the position of (0,0) I get 1.1175871e-08 while the result I get in matlab is -0.9639

In Matlab:

A = [1,2,3,4; 1,2,3,4; 1,2,3,4]; 
k = [-0.014, -0.45, 0, 0.4, 0.01];
conv2(A, k, 'same');

In opencv/c++:

cv::Mat dst; 
cv::Mat kernel;    
float K[5] = {-0.014, -0.45, 0, 0.4, 0.01}; 
cv::Mat kernel(1, 5, CV_32F, K);

float test[3][4] = {{1, 2, 3, 4},{1, 2, 3, 4},{1, 2, 3, 4}}; 
cv::Mat myMat(3, 4, CV_32FC1, &test);

filter2D(myMat, dst, -1 , kernel , Point( -1, -1 ), 0, BORDER_DEFAULT);

What am I doing wrong in the opencv code?

filter2d vs conv2

The result I get from conversion of conv2 function in matlab is very different from the result I get in opencv using filter2d function. In opencv in the position of (0,0) I get 1.1175871e-08 while the result I get in matlab is -0.9639

In Matlab:

A = [1,2,3,4; 1,2,3,4; 1,2,3,4]; [1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6]; 
k = [-0.014, -0.45, 0, 0.4, 0.01];
0.45, 0.014];
conv2(A, k, 'same');

In opencv/c++:

cv::Mat dst; 
cv::Mat kernel;    
float K[5] = {-0.014, -0.45, 0, 0.4, 0.01}; 0.45, 0.014}; 
cv::Mat kernel(1, 5, CV_32F, K);

float test[3][4] = {{1, 2, 3, 4},{1, 4,5,6},{1, 2, 3, 4},{1, 4,5,6},{1, 2, 3, 4}}; 
4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6}};
cv::Mat myMat(3, 4, CV_32FC1, &test);

filter2D(myMat, dst, -1 , kernel , Point( -1, -1 ), 0, BORDER_DEFAULT);

What am I doing wrong in the opencv code?

filter2d vs conv2

The result I get from conversion of conv2 function in matlab is very different from the result I get in opencv using filter2d function. In opencv in the position of (0,0) I get 1.1175871e-08 while the result I get in matlab is -0.9639

In Matlab:

A = [1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6]; 
k = [-0.014, -0.45, 0, 0.45, 0.014];
conv2(A, k, 'same');

In opencv/c++:

cv::Mat dst; 
cv::Mat kernel;    
float K[5] = {-0.014, -0.45, 0, 0.45, 0.014}; 
cv::Mat kernel(1, 5, CV_32F, K);

float test[3][4] test[6][6] = {{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6}};
cv::Mat myMat(3, 4, CV_32FC1, &test);

filter2D(myMat, dst, -1 , kernel , Point( -1, -1 ), 0, BORDER_DEFAULT);

What am I doing wrong in the opencv code?

filter2d vs conv2

The result I get from conversion of conv2 function in matlab is very different from the result I get in opencv using filter2d function. In opencv in the position of (0,0) I get 1.1175871e-08 while the result I get in matlab is -0.9639

In Matlab:

A = [1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6]; 
k = [-0.014, -0.45, 0, 0.45, 0.014];
conv2(A, k, 'same');

In opencv/c++:

cv::Mat dst; 
cv::Mat kernel;    
float K[5] = {-0.014, -0.45, 0, 0.45, 0.014}; 
cv::Mat kernel(1, 5, CV_32F, K);

float test[6][6] = {{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6}};
cv::Mat myMat(3, 4, CV_32FC1, &test);

filter2D(myMat, dst, -1 , kernel , Point( -1, -1 ), 0, BORDER_DEFAULT);

What am I doing wrong in the opencv code?

filter2d vs conv2

The result I get from conversion of conv2 function in matlab is very different from the result I get in opencv using filter2d function. In opencv in the position of (0,0) I get 1.1175871e-08 while the result I get in matlab is -0.9639

In Matlab:

A = [1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6; 1,2,3,4,5,6]; 
k = [-0.014, -0.45, 0, 0.45, 0.014];
conv2(A, k, 'same');

In opencv/c++:

cv::Mat dst; 
float K[5] = {-0.014, -0.45, 0, 0.45, 0.014}; 
cv::Mat kernel(1, 5, CV_32F, K);
Mat kernel-p(1,5, CV_32F);
cv::flip(kernel, kernel-p, -1);

float test[6][6] = {{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6},{1, 2, 3, 4,5,6}};
cv::Mat myMat(3, 4, CV_32FC1, &test);

filter2D(myMat, dst, -1 , kernel , Point( -1, -1 ), 0, BORDER_DEFAULT);

What am I doing wrong in the opencv code?