I've started to use OpenCV with Visual C++ 2010 Express, because it was supposed to be faster than MATLAB.
In order to do a fair comparison between both, I'm running a program where I convert a RGB image to its gray scale correspondent and I calculate the conversion image space operation elapsed time.
Using cvtColor command to do the task in C++ Release, it takes me around 5 ms, average. Doing the same operation in MATLAB, takes me more or less the same average time (the codes are bellow).
I already tested, and both programs are working fine.
Does anybody have any idea if I can improve the OpenCV speed?
C++ code.
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include <windows.h>
using namespace cv;
using namespace std;
double PCFreq = 0.0;
__int64 CounterStart = 0;
void StartCounter()
{
LARGE_INTEGER li;
if(!QueryPerformanceFrequency(&li))
cout << "QueryPerformanceFrequency failed!\n";
PCFreq = double(li.QuadPart)/1000.0;
QueryPerformanceCounter(&li);
CounterStart = li.QuadPart;
}
double GetCounter()
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return double(li.QuadPart-CounterStart)/PCFreq;
}
int main()
{
double time;
Mat im, result;
im = imread("C:/Imagens_CV/circles_rgb.jpg");
StartCounter();
cvtColor(im,result, CV_BGR2GRAY);
time = GetCounter();
cout <<"Process time: "<< time << endl;
}
MATLAB code
tic
img_gray = rgb2gray(img_rgb);
toc
