我刚刚建立了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
答案 0 :(得分:0)
对不起中断。
我只是将MarkerSize设置为正值(在我的情况下为0.05f,默认为-1)。出现任何轮换和翻译!
答案 1 :(得分:0)
Rvec和Tvec首先必须进行初始化。 您可以通过在marker中调用calculateExtrinsics()函数来完成此操作。如果在MarkerDetector的detect()函数中设置标记大小,将自动调用calculateExtrinsics()函数。
答案 2 :(得分:0)
您需要使用ChArUco Boards或ArUco Boards校准相机,一旦获得输出文件camera.yml。您可以将其与当前的应用程序一起使用。如果没有校准文件,则不会计算Txyz和Rxyz。