Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

OpenCV undistort improved performance

$
0
0

Hi
I'd like to share an improvement I just discovered concerning radial undistortion of images.

I had performance issues with ofxCvImage::undistort, a very annoying FPS drop.
I never digged into that but I just found that it was using cvUnDistortOnce() which is creating the "undistortion map" each frame.
For my video camera feed, it was not necessary,
So I created a new func undistortFixedParam() which creates the map only on first time, and uses that map for each next frames.

Here is the code

//--------------------------------------------------------------------------------
void ofxCvImage::undistortFixedParam( float radialDistX, float radialDistY,
                           float tangentDistX, float tangentDistY,
                           float focalX, float focalY,
                           float centerX, float centerY ){
    
    if( !bAllocated ){
        ofLogError("ofxCvImage") << "undistort(): image not allocated";
        return;
    }
   
    if (!bHasUndistortionMap)
    {
        float camIntrinsics[] = { focalX, 0, centerX, 0, focalY, centerY, 0, 0, 1 };
        float distortionCoeffs[] = { radialDistX, radialDistY, tangentDistX, tangentDistY };
  
        cvUnDistortInit(cvImage, cvUndistortionMap, camIntrinsics, distortionCoeffs, 1);
        
        bHasUndistortionMap = true;
    }
    
    cvUnDistort(cvImage, cvImageTemp, cvUndistortionMap, 1);
    swapTemp();
    flagImageChanged();
}

I have now a huge better performance.
It was a really simple improvement, but I'd like to share it because not so obvious to find references about it.


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>