As a follow up to my post yesterday on using transparent PNG overlays with OpenCV and wxPython, I tweaked my Python script slightly so that it would record and display the average frames per second of the video feed. I then ported the script into C++ as closely as possible so that I could compare apples-to-apples the performance of OpenCV on Python vs C++ (see the code attached at the end if you’re interested in that sort of thing).
I ran four tests, each for 600 seconds, and computed the average frames per second of the resulting video feed from my integrated webcam. I tabulated the results in the table below:
Framework | No Overlay | With Overlay | % Change |
Python 2.7, OpenCV 2.4 | 19.82 fps | 6.26 fps | -68.4% |
C++ (compiled in VS2010), OpenCV 2.4 | 23.95 fps | 23.94 fps | -0.04% |
% Improvement | 20.8% | 282.6% |
Without using transparent overlays, C++ yields a few more frames per second than Python. As an interpreted language, I would expect Python to be slightly slower, but I think it performed admirably anyhow as the difference in frame rates were unnoticeable (even if it is 21% slower than C++).
But when transparent overlays are introduced, Python slows down to a ridiculous 6 frames per second while C++ doesn’t even miss a beat. Again, I would have expected Python to be slower, but a 68% performance drop? Outrageous, considering that C++ is unaffected.
There could be something going on with the Python wrapper for OpenCV’s cvGet2D and cvSet2D that is eating up resources and slowing everything down to a crawl, but I don’t really think I’ll make life easier by slogging through the code and identifying issues.
The takeaway here is that I’m at a crossroads with the software design: if I stick with the all-too-easy Python/wxPython/OpenCV framework, then I have to accept a user interface that avoids overlays or any kind of image analysis. Alternately, if I want a better user interface with overlays and possibly some image analysis, then I have no choice but to convert everything to a much more complex C++/wxWidgets/OpenCV framework.
Hmmm. Much to think about.