Aruco奇怪的Z轴绘制

问题描述

我一直在尝试解决此问题,但是我找不到问题所在。 Image is here!不管标记相对于相机成什么角度,Z轴始终从左上角开始。

我主要遵循here提供的代码,直到姿势估计都很好为止。然后,我发现 another post提到了错误的校准,因此我废弃了之前的相机校准代码,并使用了OpenCV lib随附的示例代码。我使用ChArUco板进行了校准,并获得了相似的cameraMatrix参数,但仍然无法解决问题。

我尝试运行在OpenCV库中找到的example_aruco_detect_markers.exe,并使用charuco校准参数,它运行良好。有人可以指出错误吗?

谢谢!

cameraMatrix and distCoefficients values from charuco calibration:
3
3
6.1281775951664292e+02
0
3.2562786642941285e+02
0
6.1063209706919008e+02
2.4533932079963614e+02
0
0
1
5
1
8.3874469408101907e-02
-1.2335583906210612e-02
-3.5221660057632941e-03
1.7090716825533996e-03
-8.5416258423982583e-01

#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/aruco.hpp>
#include <opencv2/aruco/charuco.hpp>

#include <sstream>
#include <iostream>
#include <fstream>

using namespace cv;
using namespace std;

const float arucoSize = 0.13129f; //12.90mm

bool loadCameraCalibration(string name,Mat cameraMatrix,Mat distCoefficients)
{
    ifstream inStream(name);
    if (inStream)
    {
        //cameraMatrix
        uint16_t rows;
        uint16_t columns;

        inStream >> rows;
        inStream >> columns;

        cameraMatrix = Mat(Size(rows,columns),CV_64F);

        for (int r = 0; r < rows; r++)
        {
            for (int c = 0; c < columns; c++)
            {
                double read = 0.0f;
                inStream >> read;
                cameraMatrix.at<double>(r,c) = read;
                cout << cameraMatrix.at<double>(r,c) << "\n";
            }
        }

        //distCoefficients
        inStream >> rows;
        inStream >> columns;

        distCoefficients = Mat::zeros(rows,columns,CV_64F);

        for (int r = 0; r < rows; r++)
        {
            for (int c = 0; c < columns; c++)
            {
                double read = 0.0f;
                inStream >> read;
                distCoefficients.at<double>(r,c) = read;
                cout << distCoefficients.at<double>(r,c) << "\n";
            }
        }

        inStream.close();
        return true;
    }
    return false;
}

int startWebcamMonitoring(Mat &cameraMatrix,Mat &distCoefficients,float arucoSquareDimension)
{
    Mat frame;

    vector<int> markerIds;
    vector<vector<Point2f>> markerCorners,rejectedCandidates;
    vector<Vec3d> rotationVectors,translationVectors;
    aruco::DetectorParameters parameters;

    Ptr<aruco::Dictionary> markerDictionary = aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME::DICT_4X4_50);

    //show video with aruco
    VideoCapture vid(0);

    if (!vid.isOpened())
    {
        cout << "error: Webcam connect unsuccessful\n";
        return -1;
    }

    namedWindow("Webcam",WINDOW_AUTOSIZE);

    while (true)
    {
        if (!vid.read(frame))
            break;

        //cvtColor(frame,frame,COLOR_BGR2GRAY);

        aruco::detectMarkers(frame,markerDictionary,markerCorners,markerIds);
        aruco::estimatePoseSingleMarkers(markerCorners,arucoSquareDimension,cameraMatrix,distCoefficients,rotationVectors,translationVectors);

        for (int i = 0; i < markerIds.size(); i++)
        {
            aruco::drawAxis(frame,rotationVectors[i],translationVectors[i],0.1f);
            aruco::drawDetectedMarkers(frame,markerIds);

            cout << translationVectors[i] << "; " << rotationVectors[i] << endl;
        }

        imshow("Webcam",frame);
        if (waitKey(30) >= 0) break;
    }
    return 1;
}

int main(int argv,char** argc)
{
    Mat cameraMatrix = Mat::eye(3,3,CV_64F);
    Mat distCoefficients;

    loadCameraCalibration("Lenovo-charuco",distCoefficients);
    startWebcamMonitoring(cameraMatrix,arucoSize);

    return 0;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...