Ask Your Question
0

Easiest way to overload OpenCV function

asked 2019-01-28 07:05:09 -0600

Grillteller gravatar image

Hi,

what is the easiest way to overload an OpenCV function on my computer?
I want to use the function cv::findEssentialMat with two different camera matrices. At the moment this is not implemented in the standard five-point.cpp .(https://github.com/opencv/opencv/blob/master/modules/calib3d/src/five-point.cpp). Nevertheless it would be very easy to overload the function using two different camera models. I do not come from a programming background so would it be possible if I just add an overloaded function with additional camera matrices to the data file five-point.cpp in my build directory on my pc?
Or can I send a request to someone to implement it? Only around 5 lines of code would have to be changed. For me it seems it would be a lot of work if I code the complete five-point algorithm in combination with RANSAC myself.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-01-28 08:56:36 -0600

kbarni gravatar image

updated 2019-01-28 08:57:56 -0600

Yes, it's very easy; just as you imagined to do it. Add a new function after the current one in the five-point.cpp file:

cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, InputArray _cameraMatrix1, InputArray _cameraMatrix2, int method, double prob, double threshold, OutputArray _mask)

then recopy everything by duplicating each line containing cameraMatrix. E.g.:

_cameraMatrix1.getMat().convertTo(cameraMatrix1, CV_64F);
_cameraMatrix2.getMat().convertTo(cameraMatrix2, CV_64F);

same with the CV_ASSERT line and create fx1,cx1,fx2,cx2 from cameraMatrix1 and cameraMatrix2. Finally:

points1.col(0) = (points1.col(0) - cx1) / fx1;
points2.col(0) = (points2.col(0) - cx2) / fx2;
points1.col(1) = (points1.col(1) - cy1) / fy1;
points2.col(1) = (points2.col(1) - cy2) / fy2;

Then add the function declaration to the calib3d.hpp file after the original function declaration (around line 1698). Normally this should be all.

Recompile OpenCV, reinstall and enjoy :)

edit flag offensive delete link more

Comments

Is it possible that I only recompile the calib3d.hpp and the five-point.cpp using OpenCV 3.2.0 under OS Windows 10? How would I do that?

Grillteller gravatar imageGrillteller ( 2019-01-29 06:27:50 -0600 )edit
1

Not really. In Windows all the library is in opencv_world320.dll and .lib, so all the library needs to be built.

Of course if you already built it once, then only the modified cpp files will be recompiled, and then the final library will be rebuilt.

kbarni gravatar imagekbarni ( 2019-01-30 08:36:29 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-28 07:05:09 -0600

Seen: 399 times

Last updated: Jan 28 '19