1 | initial version |
I think you ask too much precision :
float markerLength=5;
std::vector<cv::Vec3f> ptMarker={ cv::Vec3f(-markerLength / 2.f, markerLength / 2.f, 0),cv::Vec3f(markerLength / 2.f, markerLength / 2.f, 0),
cv::Vec3f(markerLength / 2.f, -markerLength / 2.f, 0),cv::Vec3f(-markerLength / 2.f, -markerLength / 2.f, 0) };
params->cornerRefinementMethod = cv::aruco::CORNER_REFINE_CONTOUR;
cv::aruco::detectMarkers(frame, dict, markerCorners, markerIds, params);
auto numMarkers = markerIds.size();
if (numMarkers > 0)
{
cv::aruco::drawDetectedMarkers(debugFrame, markerCorners, markerIds);
cv::aruco::estimatePoseSingleMarkers(markerCorners, markerLength, camMatrix, distortionCoeffs, rotationVec, translationVec);
for (int i = 0; i < numMarkers; i++)
{
// Official aruco axis drawing.
cv::Mat imagePt;
cv::aruco::drawAxis(debugFrame, camMatrix, distortionCoeffs, rotationVec[i], translationVec[i], 0.5 * 5.0);
std::cout << "\n Corners =" << markerCorners[i];
cv::projectPoints(ptMarker, rotationVec, translationVec, camMatrix, distortionCoeffs,imagePt);
std::cout<<"\n ImagePt = "<<imagePt;
std::cout << "\n R = "<<rotationVec[i] <<"\n T="<< translationVec[i];
for (int j=0;j<ptMarker.size();j++)
std::cout<<"\n"<<cv::norm(imagePt.at<cv::Point2f>(j,0)-markerCorners[i][j]);
and results are :
Corners =[1496.3776, 612.07306;
1403.8204, 682.23145;
1313.486, 596.70477;
1406.4631, 528.42938]
ImagePt = [1496.5664, 611.73926;
1403.6193, 682.58307;
1313.7218, 596.35846;
1406.2395, 528.75714]
R = [0.947205, 2.69749, -0.830918]
T=[17.252, 2.48271, 90.3606]
0.383516
0.405104
0.418991
0.396784
Corners =[1486.0046, 613.57391;
1404.2153, 674.97919;
1323.6996, 599.35333;
1405.9072, 538.94623]
ImagePt = [1486.1536, 613.17859;
1404.0493, 675.38696;
1323.8932, 598.95392;
1405.7307, 539.33258]
R = [0.941276, 2.68412, -0.831723]
T=[19.4103, 2.88188, 101.679]
0.422446
0.440275
0.443862
0.424765
corners and imagePt distance is less than a pixel
2 | No.2 Revision |
I think you ask too much precision :
float markerLength=5;
std::vector<cv::Vec3f> ptMarker={ cv::Vec3f(-markerLength / 2.f, markerLength / 2.f, 0),cv::Vec3f(markerLength / 2.f, markerLength / 2.f, 0),
cv::Vec3f(markerLength / 2.f, -markerLength / 2.f, 0),cv::Vec3f(-markerLength / 2.f, -markerLength / 2.f, 0) };
params->cornerRefinementMethod = cv::aruco::CORNER_REFINE_CONTOUR;
params->adaptiveThreshConstant=true;
cv::aruco::detectMarkers(frame, dict, markerCorners, markerIds, params);
auto numMarkers = markerIds.size();
if (numMarkers > 0)
{
cv::aruco::drawDetectedMarkers(debugFrame, markerCorners, markerIds);
cv::aruco::estimatePoseSingleMarkers(markerCorners, markerLength, camMatrix, distortionCoeffs, rotationVec, translationVec);
for (int i = 0; i < numMarkers; i++)
{
// Official aruco axis drawing.
cv::Mat imagePt;
cv::aruco::drawAxis(debugFrame, camMatrix, distortionCoeffs, rotationVec[i], translationVec[i], 0.5 * 5.0);
std::cout << "\n Corners =" << markerCorners[i];
cv::projectPoints(ptMarker, rotationVec, translationVec, camMatrix, distortionCoeffs,imagePt);
std::cout<<"\n ImagePt = "<<imagePt;
std::cout << "\n R = "<<rotationVec[i] <<"\n T="<< translationVec[i];
for (int j=0;j<ptMarker.size();j++)
std::cout<<"\n"<<cv::norm(imagePt.at<cv::Point2f>(j,0)-markerCorners[i][j]);
and results are :
Corners =[1496.3776, 612.07306;
1403.8204, 682.23145;
1313.486, 596.70477;
1406.4631, 528.42938]
=[1496.6306, 612.09216;
1403.8015, 682.35718;
1313.5145, 596.81036;
1406.2969, 528.19458]
ImagePt = [1496.5664, 611.73926;
1403.6193, 682.58307;
1313.7218, 596.35846;
1406.2395, 528.75714]
[1496.7004, 611.69116;
1403.7068, 682.76807;
1313.6329, 596.41217;
1406.2034, 528.58215]
R = [0.947205, 2.69749, -0.830918]
T=[17.252, 2.48271, 90.3606]
0.383516
0.405104
0.418991
0.396784
[0.948757, 2.69793, -0.828673]
T=[17.2317, 2.47978, 90.2495]
0.407035
0.421666
0.415426
0.398693
Corners =[1486.0046, 613.57391;
1404.2153, 674.97919;
1323.6996, 599.35333;
1405.9072, 538.94623]
=[1496.6405, 614.14752;
1403.9784, 684.52588;
1313.4429, 598.77551;
1406.4125, 530.15881]
ImagePt = [1486.1536, 613.17859;
1404.0493, 675.38696;
1323.8932, 598.95392;
1405.7307, 539.33258]
[1496.7953, 613.77832;
1403.8063, 684.91089;
1313.6472, 598.3988;
1406.2253, 530.51898]
R = [0.941276, 2.68412, -0.831723]
T=[19.4103, 2.88188, 101.679]
0.422446
0.440275
0.443862
0.424765
[0.948401, 2.69694, -0.827097]
T=[17.223, 2.55703, 90.191]
0.400335
0.421732
0.428564
0.405882
corners and imagePt distance is less than a pixel