OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 13 Oct 2018 05:49:45 -0500filter2d vs conv2http://answers.opencv.org/question/201072/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?tinahomSat, 13 Oct 2018 05:49:45 -0500http://answers.opencv.org/question/201072/How to smooth the edges of a low quality image?http://answers.opencv.org/question/164533/how-to-smooth-the-edges-of-a-low-quality-image/ I am working on this picture.
![Google Map Satellite Image](/upfiles/14993375227217035.jpg)
Due to its bad quality, firstly I use histogram equalization after that bilateral blur to preserve the edges, adaptive Canny and edge sharpening kernel and the output is this:-
![Edge detection](/upfiles/14993377797972683.png)
I need the edges to be closed and gone through morphological operations but the results were not satisfactory and the operation can't be generalized on all the images. How to solve this?
Here's the code:-
[Edge Sharp](https://drive.google.com/open?id=0B4EyyXU6mOf5Z0hBbW4xYUZZTzQ)akash29Thu, 06 Jul 2017 05:49:04 -0500http://answers.opencv.org/question/164533/filter2d BORDER_WRAP on certain texturefilterhttp://answers.opencv.org/question/146025/filter2d-border_wrap-on-certain-texturefilter/ I am running filter2d on an image with a filter that I was given. I have several filters, ranging from 3_3_5bit to 17_17_12bit. For some reason, whenever I run my software on a filter that has dimensions smaller than 9, I will received this error:
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/B3p0_301755_83026/build-maci64.maci64.301755.r000/B3p0/maci64/OpenCV/modules/imgproc/src/filter.cpp:166: error: (-215) columnBorderType != BORDER_WRAP in function init
Abort trap: 6
My program works for all other filters, except for any smaller than 9. However, these filters will work on any different bordertype, other than WRAP, but to have my software do its job, it needs BORDER_WRAP. Any help would be greatly greatly appreciated! If code would be helpful to see, I can show somemlanusFri, 05 May 2017 04:09:58 -0500http://answers.opencv.org/question/146025/Cuda Convolve VS filter2D openCV 3.1.0http://answers.opencv.org/question/120598/cuda-convolve-vs-filter2d-opencv-310/Hello, I'm using OpenCV 3.1.0 with CUDA on Intel Xeon 5110 @ 1.60 Ghz x2 CPU + Nvidia Quadro 600 + 4GB RAM with Qt on Fedora 23 OS and I'm concerned about convolution speed.
What I've got from my test code is that filter2D convolution of an image with a 3x3 kernel is much faster than cuda Convolve as far as the image size is not too big (threshold around 1280x1024) and surprisingly always faster than separate convolution (first with 3x1 then 1x3 kernels), I was expecting from theory 2/3 processing time (3+3 rather than 3x3). Moreover the output image size with cuda convolve is smaller than the original one, I was expecting same size from documentation.
Is there anything wrong in what I'm doing? Any suggestion to speed up convolution for images around 640x480?
You can find below the test code I used:
cv::cuda::GpuMat temp2; // ---- is a B/W image different size
//-----fill up the temp2 image
....
//---------------------------
Mat dst_x;
Mat dst_x1;
Mat dst_x2;
Mat tmp_2;
cv::cuda::GpuMat fx;
Mat kernel_x = (Mat_<double>(3,3) << 2, 0, -2, 4, 0, -4, 2, 0, -2);
Mat kernel_x1 = (Mat_<double>(3,1) << 2, 4, 2); //----separate x convolution
Mat kernel_x2 = (Mat_<double>(1,3) << 1, 0, -1);
temp2.download(tmp_2);
int64 t1 = getTickCount();
cv::filter2D(tmp_2, dst_x1, -1,kernel_x1);
cv::filter2D(dst_x1, dst_x2, -1,kernel_x2);
int64 t2 = getTick();
std::cout << "Time passed in ms: " << (((t2 - t1) / 1e9)*1000.) << std::endl;
//int64 t1 = getTickCount();
cv::filter2D(tmp_2, dst_x, -1,kernel_x);
//int64 t2 = getTick();
//std::cout << "Time passed in ms: " << (((t2 - t1) / 1e9)*1000.) << std::endl;
//----CUDA convolution---------
kernel_x.convertTo(kernel_x,CV_32FC1);
//int64 t1 = getTickCount();
Ptr<cuda::Convolution> convolver = cuda::createConvolution(Size(3, 3));
convolver->convolve(temp2, kernel_x, fx);
//int64 t2 = getTick();
//std::cout << "Time passed in ms: " << (((t2 - t1) / 1e9)*1000.) << std::endl;
//----END CUDA convolution---------
I can sum up the results as follows:
Image size (30,40) (rows,cols)
Time passed in ms: 0.083827filter2D convolution with kernel size (3,3)output image same size
Time passed in ms: 0.044761filter2D separated convolution with kernel size (1,3) and (3,1)output image same size
Time passed in ms: 5.95849CUDA convolve convolution with kernel size (3,3)output image size (28,38);
Image size (118,158)
Time passed in ms: 0.204968filter2D convolution with kernel size (3,3)output image same size
Time passed in ms: 0.27658filter2D separated convolution with kernel size (1,3) and (3,1)output image same size
Time passed in ms: 7.03869CUDA convolve convolution with kernel size (3,3)output image size (116,156);
Image size (469,629)
Time passed in ms: 2.51682filter2D convolution with kernel size (3,3)output image same size
Time passed in ms: 5.72645filter2D separated convolution with kernel size (1,3) and (3,1)output image same size
Time passed in ms: 9.31991CUDA convolve convolution with kernel size (3,3)output image size (467,627);
federocchiThu, 29 Dec 2016 12:22:23 -0600http://answers.opencv.org/question/120598/is it possible to apply convolution in multiple dimensions?http://answers.opencv.org/question/82821/is-it-possible-to-apply-convolution-in-multiple-dimensions/I would like to know if there is any function to apply convolution in more than 2 dimensions in Opencv. I know that there is the `filter2d()` but this one is limited in 2d right? So I was wondering if there is something similar to [`convn`](http://www.mathworks.com/help/matlab/ref/convn.html) in matlab which allows you to apply convolution in more dimensions.theodoreFri, 08 Jan 2016 05:20:57 -0600http://answers.opencv.org/question/82821/