Ask Your Question

augustt198's profile - activity

2016-02-16 09:10:20 -0600 received badge  Enthusiast
2016-02-09 19:07:52 -0600 commented answer Rotating target changes distances computed with solvePnP

The contour points are displayed in this gif: Is there a method for consistently ordering the points?

I've also changed the object points to match the size of the real-life target in inches.

2016-02-08 11:02:10 -0600 received badge  Editor (source)
2016-02-06 22:48:29 -0600 asked a question Rotating target changes distances computed with solvePnP

I've been working on finding the distance to a target (of known real-world dimensions). The distance seems consistent enough when viewed from a forward-facing angle, but when I rotate the target (without translating it) the distance changes:

image description

Here is the relevant code:

vector<Point3f> objectPoints;
objectPoints.push_back(Point3f(-1, -1, 0));
objectPoints.push_back(Point3f(-1, 1, 0));
objectPoints.push_back(Point3f(1, 1, 0));
objectPoints.push_back(Point3f(1, -1, 0));
Mat objectPointsMat(objectPoints);

Mat rvec;
Mat tvec;
solvePnP(objectPointsMat, inputContour, cameraMatrix, distortionCoeffs, rvec, tvec);

double tx =<double>(0, 0);
double ty =<double>(1, 0);
double tz =<double>(2, 0);
double dist = std::sqrt(tx*tx + ty*ty + tz*tz);

char *str;
asprintf(&str, "DIST = %7.3f", dist);
putText(original, str, Point(0, original.size().height), CV_FONT_HERSHEY_PLAIN,
    3, Scalar(255, 255, 255), 3);

EDIT: As Eduardo suggested, I have drawn the computed prose. I have also changed the objects points to match the width/height ratio of the actual target using:

objectPoints.push_back(Point3f(-1, -0.7, 0));
objectPoints.push_back(Point3f(-1, 0.7, 0));
objectPoints.push_back(Point3f(1, 0.7, 0));
objectPoints.push_back(Point3f(1, -0.7, 0));

The issue is that while yawing seems to work now, rolling makes the distance jump: image description