Different run time for Morphological operations in OpenCV 2410 and OpenCV 310

asked 2017-03-19 08:04:23 -0500


I'm running the same code for morphological "OPEN" operation as below:

include "opencv.hpp"

include <chrono>

using namespace cv;

void main() { Mat Image; Image = Mat::zeros(5000, 5000, CV_8UC3) ;

Mat element = getStructuringElement(MORPH_RECT, Size(1000, 1), Point(-1,-1));

auto begin = std::chrono::high_resolution_clock::now();
morphologyEx(Image, Image, MORPH_OPEN, element);
auto end = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count()/1000000 << "ms" << std::endl;


However, the same code runs very different in terms of runtime with OPENCV 2410 and OPENCV 310. (both 64 bit) In 2410 it takes ~500ms, but in 310 it akes more than 5 seconds! 2410 also outperforms the 310 for other different kernel sizes.

Would appreciate if someone has seen such a problem...

Thank you, Alex.

edit retag flag offensive close merge delete


You are doing a single iteration. That is a bad test. Try doing 1000 iterations and seeing if that works.

Also, did you build 310 with OpenCL where it is using the GPU and the first iteration has to initialize all of that?

Tetragramm gravatar imageTetragramm ( 2017-03-19 08:32:36 -0500 )edit

Actually I run 100 iterations. The result is the same per each one of them. OPENCV is built without OPENCL/CUDA support.

spivakoa gravatar imagespivakoa ( 2017-03-19 09:05:12 -0500 )edit

Ok, I just tested with 320 and 2413, and 320 was faster by a couple of percentage points. You probably have different settings. What's different I don't know, but something must be.

Tetragramm gravatar imageTetragramm ( 2017-03-19 15:05:26 -0500 )edit

And 2410 was was a couple percentage points worse than 2413, so yeah, definitely something going on with your setup.

Tetragramm gravatar imageTetragramm ( 2017-03-19 15:23:14 -0500 )edit