Ask Your Question

federocchi's profile - activity

2020-04-14 02:03:36 -0600 received badge  Famous Question (source)
2018-04-20 16:14:52 -0600 received badge  Notable Question (source)
2017-10-09 14:34:41 -0600 received badge  Popular Question (source)
2016-12-29 12:22:23 -0600 asked a question Cuda Convolve VS filter2D openCV 3.1.0

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.083827filter2D convolution with kernel size (3,3)output image same size

Time passed in ms: 0.044761filter2D separated convolution with kernel size (1,3) and (3,1)output image same size

Time passed in ms: 5.95849CUDA convolve convolution with kernel size (3,3)output image size (28,38);

Image size (118,158)

Time passed in ms: 0.204968filter2D convolution with kernel size (3,3)output image same size

Time passed in ms: 0.27658filter2D separated convolution with kernel size (1,3) and (3,1)output image same size

Time passed in ms: 7.03869CUDA convolve convolution with kernel size (3,3)output image size (116,156);

Image size (469,629)

Time passed in ms: 2.51682filter2D convolution with kernel size (3,3)output image same size

Time passed in ms: 5.72645filter2D separated convolution with kernel size (1,3) and (3,1)output image same size

Time passed in ms: 9.31991CUDA convolve convolution with kernel size (3 ... (more)

2016-11-30 11:20:28 -0600 received badge  Enthusiast
2016-06-16 02:35:19 -0600 commented question openCV 3.1.0 videocapture can't open a video

It was a building issue, as far as I can see a it's a very popular issue with opencv rel. 3.x.0, see: stackoverflow The videoio lib was probably built without ffmpeg due to a blank ffmpeg_version.cmake file while generating with CMake. It was misleading that the cmake configuration output reported FFMPEG: YES (prebuilt binaries) but I missed that all the other stuff like codec, format, etc where with NO instead of YES with version (i.e. ver 55.18.102).

2016-06-13 10:03:33 -0600 received badge  Editor (source)
2016-06-13 08:47:22 -0600 asked a question openCV 3.1.0 videocapture can't open a video

Hello, I've installed opencv 3.1.0, building on my own with visual studio 2010 and everything is working but videocapture, compiling but not running; I've tried all I could find on the net (updated K-lite codecs and put the opencv_ffmpeg310_64.dll in the compiler directory C:\opencv\build\x64\vc10\bin)

The simple test code I'm using:

#include <iostream> #include <fstream> #include <opencv2 videoio.hpp=""> #include <opencv2 highgui.hpp=""> #include <opencv2 imgproc.hpp=""> using namespace cv; using namespace std;

int main(int argc, char** argv) {

Mat imagex;
imagex = imread("C:/opencv/data/test.png", IMREAD_COLOR); // Read the file     


if( imagex.empty() ) // Check for invalid input     
{         
    cout << "Could not open or find the image" << std::endl ;         
    return -3;

}
else 
cout << "image opened" << std::endl ;


 ifstream myfile;
 myfile.open ("C:/opencv/data/pictCh0_0.yuv", ios::binary|ios::ate); //open the yuv422 file


 if (!myfile.is_open()) { 
    fprintf(stderr, "error: unable to open file"); 
    return 1; 
 }
 else 
 cout << "file opened" << std::endl ;



 // Open a video file:
 cv::VideoCapture cap("C:/opencv/data/test.avi");
 if(!cap.isOpened()) {
     std::cout << "Unable to open the camera\n";
     std::exit(-1);
 }

...... etc......

it reads the image and the binary file but not the video and I've tried any kind of video, also the same test.pgn image read by imread. I tried to debug but no errors, simply it does not load anything. The most annoying thing is that with the pre-built libraries 3.1.0 it runs even though in the compiler directory only but I can't use them because they don't support CUDA... Any clue? Thanks in advance.