0

我刚刚构建了 aruco 1.3.0,并且 aruco_test 完美运行。

到目前为止,我尝试使用 Opencv + kinect v2 获取标记。检测到标记,但没有旋转和平移。有人遇到过类似的问题吗?

#include <iostream>

// OpenCV Header
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>  
#include "opencv2/imgproc/imgproc.hpp"
#include <aruco.h>

// Kinect for Windows SDK Header
#include <Kinect.h>

using namespace std; 
using namespace aruco;
using namespace cv;

float TheMarkerSize = -1;
int ThePyrDownLevel;
MarkerDetector MDetector; 
vector< Marker > TheMarkers; 
CameraParameters TheCameraParameters;   


int main(int argc, char** argv)
{
    TheCameraParameters.readFromXMLFile("camera.yml"); 
    if (ThePyrDownLevel > 0)
        MDetector.pyrDown(ThePyrDownLevel);


    MDetector.setThresholdParams(7, 7);
    MDetector.setThresholdParamRange(2, 0); 


    // 1a. Get default Sensor
    cout << "Try to get default sensor" << endl;
    IKinectSensor* pSensor = nullptr;
    if (GetDefaultKinectSensor(&pSensor) != S_OK)
    {
        cerr << "Get Sensor failed" << endl;
        return -1;
    } 

    // 1b. Open sensor
    cout << "Try to open sensor" << endl;
    if (pSensor->Open() != S_OK)
    {
        cerr << "Can't open sensor" << endl;
        return -1;
    }

    // 2a. Get frame source
    cout << "Try to get color source" << endl;
    IColorFrameSource* pFrameSource = nullptr;
    if (pSensor->get_ColorFrameSource(&pFrameSource) != S_OK)
    {
        cerr << "Can't get color frame source" << endl;
        return -1;
    }

    // 2b. Get frame description
    cout << "get color frame description" << endl;
    int     iWidth = 0;
    int     iHeight = 0;
    IFrameDescription* pFrameDescription = nullptr;
    if (pFrameSource->get_FrameDescription(&pFrameDescription) == S_OK)
    {
        pFrameDescription->get_Width(&iWidth);
        pFrameDescription->get_Height(&iHeight); 
    }
    pFrameDescription->Release();
    pFrameDescription = nullptr;

    // 3a. get frame reader
    cout << "Try to get color frame reader" << endl;
    IColorFrameReader* pFrameReader = nullptr;
    if (pFrameSource->OpenReader(&pFrameReader) != S_OK)
    { 
        cerr << "Can't get color frame reader" << endl;
        return -1;
    }

    // 2c. release Frame source
    cout << "Release frame source" << endl;
    pFrameSource->Release();
    pFrameSource = nullptr;

    // Prepare OpenCV data
    cv::Mat mImg(iHeight, iWidth, CV_8UC4);
    cv::Mat mImg2(iHeight, iWidth, CV_8UC1);
    UINT uBufferSize = iHeight * iWidth * 4 * sizeof(BYTE);
    cv::namedWindow("Color Map");

    // Enter main loop
    while (true)
    {
        // 4a. Get last frame
        IColorFrame* pFrame = nullptr;
        if (pFrameReader->AcquireLatestFrame(&pFrame) == S_OK)
        {
            cout << GetTickCount() << endl;
            // 4c. Copy to OpenCV image
            if (pFrame->CopyConvertedFrameDataToArray(uBufferSize, mImg.data, ColorImageFormat_Bgra) == S_OK)
            {
                cvtColor(mImg, mImg2, CV_BGR2GRAY);
                //camParam.resize(mImg2.size());
                MDetector.detect(mImg2, TheMarkers, TheCameraParameters, TheMarkerSize);

                if (TheMarkers.size() > 0) {
                    //for each marker, draw info and its boundaries in the image
                    for (unsigned int i = 0;i<TheMarkers.size();i++) { 
                        cout << TheMarkers[i] << endl;
                        TheMarkers[i].draw(mImg2, Scalar(0, 0, 255), 1);

                    } 
                }
                if (TheCameraParameters.isValid())
                    for (unsigned int i = 0; i < TheMarkers.size(); i++) {
                        CvDrawingUtils::draw3dCube(mImg2, TheMarkers[i], TheCameraParameters);
                        CvDrawingUtils::draw3dAxis(mImg2, TheMarkers[i], TheCameraParameters);
                    }

                cv::imshow("Color Map", mImg2);
            }
            else
            {
                cerr << "Data copy error" << endl;
            }

            // 4e. release frame
            pFrame->Release();
        }

        // 4f. check keyboard input
        if (cv::waitKey(30) == VK_ESCAPE) {
            break;
        }
    }

    // 3b. release frame reader
    cout << "Release frame reader" << endl;
    pFrameReader->Release();
    pFrameReader = nullptr;

    // 1c. Close Sensor
    cout << "close sensor" << endl;
    pSensor->Close();

    // 1d. Release Sensor
    cout << "Release sensor" << endl;
    pSensor->Release();
    pSensor = nullptr;

    return 0;
}

结果看起来像

637=(934.56,481.291) (763.227,482.706) (737.609,222.863) (907.926,266.524) Txyz=
-999999 -999999 -999999 Rxyz=-999999 -999999 -999999
87746890
637=(934.503,481.388) (763.178,482.765) (737.533,223.02) (907.796,266.664) Txyz=
-999999 -999999 -999999 Rxyz=-999999 -999999 -999999
87747390
637=(934.145,481.07) (762.71,482.473) (737.016,222.63) (907.335,266.239) Txyz=-9
99999 -999999 -999999 Rxyz=-999999 -999999 -999999
4

3 回答 3

0

抱歉打扰了。

我只是将 MarkerSize 设置为正值(在我的情况下为 0.05f,默认为 -1)。出现任何旋转和平移!

于 2016-03-16T10:12:05.920 回答
0

首先必须初始化 Rvec 和 Tvec。您可以通过在标记中调用 calculateExtrinsics() 函数来做到这一点。如果您在 MarkerDetector 的 detect() 函数中设置标记大小,则会自动调用 calculateExtrinsics() 函数。

于 2016-06-28T12:36:35.393 回答
0

您需要使用 ChArUco Boards 或仅使用 ArUco Boards 校准相机,一旦您获得输出文件 camera.yml。您可以将它与您当前的应用程序一起使用。如果没有校准文件,则不会计算 Txyz 和 Rxyz。

于 2016-07-29T05:33:54.070 回答