Estimate the pose of a position with respect to the observer using an image.
165 {
166
167
168
170
171
172 cv::Mat cvObjPoints(4, 1, CV_32FC3);
176 cvObjPoints.at<
cv::Vec3f>(3) =
cv::Vec3f{constants::ARUCO_TAG_SIDE_LENGTH, constants::ARUCO_TAG_SIDE_LENGTH, 0};
177
178
179 cv::Mat cvImgPoints(4, 1, CV_32FC3);
180 cvImgPoints.at<
cv::Vec3f>(0) =
cv::Vec3f{
static_cast<float>(stTag.pBoundingBox->x),
static_cast<float>(stTag.pBoundingBox->y), 0.0f};
182 cv::Vec3f{
static_cast<float>(stTag.pBoundingBox->x),
static_cast<float>(stTag.pBoundingBox->y + stTag.pBoundingBox->height), 0.0f};
184 cv::Vec3f{
static_cast<float>(stTag.pBoundingBox->x + stTag.pBoundingBox->width),
static_cast<float>(stTag.pBoundingBox->y), 0.0f};
185 cvImgPoints.at<
cv::Vec3f>(3) =
cv::Vec3f{
static_cast<float>(stTag.pBoundingBox->x + stTag.pBoundingBox->width),
186 static_cast<float>(stTag.pBoundingBox->y + stTag.pBoundingBox->height),
187 0.0f};
188
189
190 cv::solvePnP(cvObjPoints, cvImgPoints, cvCameraMatrix, cvDistCoeffs, cvRotVec, cvTransVec);
191
192
193 double dForward = cvTransVec[2];
194 double dRight = cvTransVec[0];
195 double dUp = cvTransVec[1];
196
197
198 stTag.dStraightLineDistance = std::sqrt(std::pow(dForward, 2) + std::pow(dRight, 2) + std::pow(dUp, 2));
199
200
201 stTag.dYawAngle = std::atan2(dRight, dForward);
202 }
bool solvePnP(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int flags=SOLVEPNP_ITERATIVE)