1 | initial version |
Use cv::solvePnP in the calib3d module. If you use the implementation CV_P3P, you need to pass in exactly 4 matching object and image points.
My use looks like the following:
cv::solvePnP(objectPoints, imagePoints, camMatrix, distCoeffs, rvec, tvec, useExtrinsicGuess, CV_ITERATIVE);
From the rvec and tvec you can get the 3D position of the camera in QR space or the 3D position of the QR code in camera space, depending on how you set things up.
You'll probably want to use cv::Rodrigues(..).
My use is this:
cv::Mat R; cv::Rodrigues(rvec, R);
I then use the following to get the position:
// Determine camera position. OpenCV uses the RIGHT HAND RULE.
// Determine the position in screen space (camera z will always be (+) using the RIGHT HAND RULE)
cv::Mat cameraCoords;
cv::gemm(R.inv(), -tvec, 1, noArray(), 1, cameraCoords);
cameraCoords is a 3x1 cv::Mat of doubles, holding x, y, and z.
2 | No.2 Revision |
Use cv::solvePnP in the calib3d module. If you use the implementation CV_P3P, you need to pass in exactly 4 matching object and image points.
My use looks like the following:
cv::solvePnP(objectPoints, imagePoints, camMatrix, distCoeffs, rvec, tvec, useExtrinsicGuess, From the rvec and tvec you can get the 3D position of the camera in QR space or the 3D position of the QR code in camera space, depending on how you set things up.
You'll probably want to use cv::Rodrigues(..).
My use is this:
cv::Mat R;
cv::Rodrigues(rvec, I then use the following to get the position:
// Determine camera position. OpenCV uses the RIGHT HAND RULE.
// Determine the position in screen space (camera z will always be (+) using the RIGHT HAND RULE) cameraCoords is a 3x1 cv::Mat of doubles, holding x, y, and z.