cvFindContours is faster than cv::findcontours
Hi, I'm using 2.4.13 opencv in a VS application and I have just updated source code changing old C functions with new C++ functions. In particular I have verified that cv::findcontours is slower than cvFindContours.
For example I have tried with that code:
for( i=0; i<10000; i++ ) {
cvThreshold(gray, tmp, 225, 255, CV_THRESH_BINARY);
cvFindContours(tmp, storage, &contours, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
cvInitTreeNodeIterator(&iterator, contours, 2);
while( src_cc= (CvSeq*)cvNextTreeNode(&iterator) ) {
for( approxParam=1.5; approxParam<=10.0; approxParam+=0.5 )
dst_cc = cvApproxPoly(src_cc, sizeof(CvContour), temp_storage, CV_POLY_APPROX_DP, approxParam);
}
}
vs
for( i=0; i<10000; i++ )
{
cv::threshold(mat_gray, mat_tmp, 225, 255, CV_THRESH_BINARY);
cv::findContours(mat_tmp, mat_contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
for( ic=0; ic<mat_contours.size(); ic++ ) {
for( approxParam=1.5; approxParam<=10.0; approxParam+=0.5 )
cv::approxPolyDP(mat_contours[ic], dst_contour, approxParam, true);
}
}
C++ source has a RELEASE execution time nearly 1 second greater than C source. Is it possible? Is it only C++ overhead? I have used an opencv sample image (baboon.jpg) and C source needs thereabouts 4 seconds while C++ source 5 seconds
regards Andrea
nice find, but please add test code to your question. so that other folks can try to reproduce it.
(also, just saying, - 2.4.8 is before-last-years-model (not really relevant any more))
I have checked it with a complex application, I need to isolate some code to post it. Let me try with 2.4.13 version, then I'll give you another feedback
Hi, I have just tried with 2.4.13 version but nothing changes. I have verified that isn't only cv::findcontours to slow down, but in general all c++ function are a little slower. For example after finding contours I use several cv::approxPolyDP to try other contours approximation and also them are slower.
How could attach a source code file I have used to test it? Anyway, doing 10000 cv::findcountours over a generic sample image and then running each contour several approximations take nearly 1 seconds more than doing it with C functions. Is it possible? Is it only C++ overhead?
After checking the source code I think it is because the
cv::findContours
not just callscvFindContours
, but after that it also copies the whole contour array from the C structure to a C++ array which has an additional overhead.And also cv::approxPolyDP allocate each time a CvMemStorage. I think I need to upgrade to 3.0 version to solve that issue, am I wrong?