0

I am working on a project in which I am given a sequence of images. The goal is to detect objects on them, segment them to extract features and eventually classify them.

The algorithm is already working, but when I compare the speed of OpenCV2.4 and OpenCV3.2 it turns out that OpenCV2.4 is approximately 2x faster than OpenCV3.2.

I use functions such as findContours, drawContours, imread, imwrite, morphology functions, etc. Is this behavior normal or am I missing something ? I thought OpenCV3.2 was supposed to be faster...

Thank you in advance. :)

  • Have you tried doing this `cv::ocl::setUseOpenCL(false);`? Probably its because of [first call overhead](http://answers.opencv.org/question/67592/opencv-30-vs-opencv-249-sobel-performance/) – Rick M. May 09 '17 at 16:32
  • I searched a bit and tried adding this line at the beginning of my code but it has not changed anything... :/ –  May 10 '17 at 07:42
  • Generally, `cv` is faster than `cv2` which is the new OpenCV-Python interface. If you are using Python and manipulating pixels, you should consider using `numpy` for calculations rather than OpenCV. Additionally, if performance is the main criteria, you should look into switching to C++. You could also make you code CUDA compatible for exploiting those multi-cores. I can look into it in detail if you add some code. – Rick M. May 10 '17 at 08:29
  • That's interesting. The problem is that the code is 2000 lines long and confidential... It's already been written and it is functionnal, my task is to improve it. Numpy won't be enough I think, because I wanted to move to OpenCV3.2 to be able to use functions not available on OpenCV2.4. Moving to C++ would also take too much time. I just simply hope there is an explanation to this slowness other than " my configuration can't allow it " (I am working on Windows 10, Python 2.7 and Visual Studio. I also have both versions of OpenCV installed on my computer) –  May 10 '17 at 12:03
  • Why do you say "Numpy won't be enough"? If you are moving to a higher version, numpy should help make it even faster. You should look at [this](https://stackoverflow.com/questions/9357696/performance-comparison-of-opencv-python-interfaces-cv-and-cv2) – Rick M. May 10 '17 at 12:09
  • That's a very interesting link ! I'm working with cv2, but I find it strange that OpenCV is taking so long to perform functions on images ; isn't it supposed to be a "image processing" library ? How do you explain that ? I said "Numpy won't be enough" because I was thinking that Numpy wouldn't have as many functions as OpenCV does. I don't want to rewrite OpenCV functions with Numpy library, it might take too much time... But on the example given (in your link) it seems that it saves a lot of time. So the best option would be to stay with OpenCV2.4 and do maximum of things with Numpy ? –  May 10 '17 at 15:19
  • `numpy` would actually help in manipulating pixel values faster. Of course you should rewrite OpenCV functions with the `numpy` library but that's for you to choose. Are you sure the `setUseOpenCL` is set to false? – Rick M. May 10 '17 at 15:21
  • Yes I set it to false at the beginning of my code... I am going to check if there is a function that returns the boolean value of 'OpenCL use', just to make sure. –  May 12 '17 at 10:20
  • But I think setUseOpenCL is useful when you work with UMat, isn't it ? I am not working with that as I use Python. –  May 12 '17 at 10:24
  • Yes I know that you are using `cv::Mat` and not `cv::UMat`, but I observed a similar behavior in my Code even if I use `cv::Mat`. – Rick M. May 12 '17 at 15:29

0 Answers0