Reputation: 5354
I need real time processing, but the internal functions of OpenCV are not providing this. I am doing hand gesture recognition, and it works almost perfectly, except for the fact that the resulting output is VERY laggy and slow. I know that this isn't because of my algorithm but the processing times of OpenCV. Is there anything I can do to speed it up?
Ps: I don't want to use the IPP libraries so please don't suggest that. I need increased performance from OpenCV itself
Upvotes: 4
Views: 12758
Reputation: 1927
I'm using some approaches:
Upvotes: 0
Reputation: 5107
Steve-o's answer is good for optimizing your code efficiency. I recommend adding some logic to monitor execution times to help you identify where to spend efforts optimizing.
OpenCV logic for time monitoring (python):
startTime = cv.getTickCount()
# your code execution
time = (cv.getTickCount() - startTime)/ cv.getTickFrequency()
Boost logic for time monitoring:
boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
// do something time-consuming
boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration timeTaken = end - start;
std::cout << timeTaken << std::endl;
How you configure your OpenCV build matters a lot in my experience. IPP isn't the only option to give you better performance. It really is worth kicking the tires on your build to get better hardware utilization.
The other areas to look at are CPU and memory utilization. If you watch your CPU and/or memory utilization, you'll probably find that 10% of your code is working hard and the rest of the time things are largely idle.
Here's an example of a parallel for loop:
cv::parallel_for_(cv::Range(0, img.rows * img.cols), [&](const cv::Range& range)
{
for (int r = range.start; r < range.end; r++)
{
int x = r / img.rows;
int y = r % img.rows;
uchar pixelVal = img.at<uchar>(y, x);
//do work here
}
});
If you're hardware constrained (ie fully utilizing CPU and/or memory), then you need to look at priotizing your process/OS perfomance optimizations/freeing system resources/upgrading your hardware
Upvotes: 1
Reputation: 12866
Traditional techniques for improving image analysis:
Upvotes: 11