Little hack for C++ function replacement in OpenCV


This is a small post on using shared library preloading for replacing a C++ function by another for filtering the OpenCV behavior. In particular we are disabling imshow.

The trick is based on LD_PRELOAD plus dlsym, and it needs to be customized by function lookup due to C++ mangling

Target:

#include <opencv2/opencv.hpp>

int main(int argc, char const *argv[])
{
 auto p = cv::imread(argv[1],0);
 cv::imshow("ciao",p);
 cv::imshow("!ciao2",p);
 cv::waitKey(0);
 return 0;
}


The source code can be found: https://github.com/eruffaldi/redirectcv

Note that for building this example uses cmakego



Comments

Popular Posts