Ask Your Question
0

Merge Mertens taking much longer on C++ than on Python on same set of images

asked 2020-04-25 07:33:44 -0500

ahmed-zubair gravatar image

HI,

I have implemented an image enhancement technique that uses Merge Mertens. I have coded it in Python and C++. On same set of images of same size and dimensions, Merge Mertens takes less than 2 seconds on Python while taking 11 seconds on C++. I want my C++ code to be faster as I have to deploy it on android devices.

Moreover, I implemented my own basic unoptimized version of exposure fusion on both Python and C++. They were both taking almost the same amount of time as Merge Mertens took in their respective languages.

Is there any reason why this is happening? How could I achieve same time as Python on C++ as speed is necessary for me as I would be using this code for android.

edit retag flag offensive close merge delete

Comments

1

The reason for this kind of problems is in 99% of cases a problem in the asker's code.

mvuori gravatar imagemvuori ( 2020-04-25 08:22:54 -0500 )edit
1

I myself thought that I must have made some silly mistake in my code. But I have checked multiple times and everything seems fine.

This is my code in Python

mergeMertens = cv.createMergeMertens()
res = mergeMertens.process(pme)

This is my code in C++

Ptr<MergeMertens> merge = createMergeMertens();
merge->process(pme, res);

Here pme is list/vector of images. I have checked its size and displayed them using imshow before passing them to the function and they are the same. However there is still difference in time taken. I am using Python 3.5 and VS2017 for C++. I am using OpenCV 4.2.0 on both platforms.

ahmed-zubair gravatar imageahmed-zubair ( 2020-04-25 09:46:04 -0500 )edit

this is disturbing. For my real-time application I put aside Python as an interpreted language in favour of compiled C++ Perhaps this executive decision was wrong?

andrei186 gravatar imageandrei186 ( 2020-04-26 03:35:30 -0500 )edit
1

How do you compile the code? You should compile using the RELEASE flag instead of DEBUG flag

HYPEREGO gravatar imageHYPEREGO ( 2020-04-26 08:24:01 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-04-29 15:09:14 -0500

ahmed-zubair gravatar image

So I just realised that I was facing this problem due to running my code in debug mode. When I switched to release mode the performance was similar to that of python. I would leave this here incase someone runs in to similar problem making same mistake as me.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-04-25 07:33:44 -0500

Seen: 72 times

Last updated: Apr 29