How to convert homogeneous points to inhomogeneous points using OpenCV (in C++)

4.7k views Asked by At

I want to convert points. At the moment my code looks like this:

std::vector<cv::Point3d> homCamPoints(4);
// some assignments to homCamPoints
std::vector<cv::Point2d> inhomCamPoints(4);
convertPointsFromHomogeneous(homCamPoints, inhomCamPoints);

But I always get an exception error concerning a memory position. So, I assume that my input type is wrong, although the OpenCV documentation is saying:

  • src – Input vector of N-dimensional points.
  • dst – Output vector of N-1-dimensional points.

That sounds like my input types are ok. However in the internet I only found examples using cv::Mat types, but due to time concerns I would like to avoid the restructuring at that stage.

I run my code in debugging mode. When calling the function the parameters really seem to be fine. The error then occures right after entering the function, but I can't figure it out exactly, as I can't get into the function code itself. Does anybody have an idea why this is not working? Thanks.

1

There are 1 answers

4
MisterC On

I tried this:

std::vector<cv::Point3d> homCamPoints(4, cv::Point3d(0,0,0));
homCamPoints[0] = cv::Point3d(0,0,0);
homCamPoints[1] = cv::Point3d(1,1,1);
homCamPoints[2] = cv::Point3d(-1,-1,-1);
homCamPoints[3] = cv::Point3d(2,2,2);

std::vector<cv::Point2d> inhomCamPoints(4);

cv::convertPointsFromHomogeneous(homCamPoints, inhomCamPoints);

and it works without exception. Maybe your Problem is somewhere else in your code. inhomCamPoints are:
[0, 0], [1, 1], [1, 1], [1, 1]