用ArUco定位代替GPS
Jul 9, 2018原文:Using Vision or Motion Capture Systems
普通单目相机调用 Aruco Library,源代码如下:
#include <opencv2/highgui.hpp>
#include "aruco.h"
using namespace std;
int main(int argc,char **argv)
{
aruco::CameraParameters camera;
camera.readFromXMLFile(argv[1]);
aruco::MarkerDetector Detector;
Detector.setDictionary("ARUCO_MIP_36h12");
cv::namedWindow( "ArUco-Pose-Estimation", cv::WINDOW_AUTOSIZE );
cv::VideoCapture cap;
cap.open(0); // open the first camera
if( !cap.isOpened() )
{ // check if we succeeded
std::cerr << "Couldn't open capture." << std::endl;
return -1;
}
cv::Mat im;
for (;;)
{
cap >> im;
if ( im.empty() )
break; // Ran out of film
auto markers=Detector.detect(im,camera,0.04);//0.102 is the marker size
for ( auto m:markers )
{
aruco::CvDrawingUtils::draw3dAxis(im,m,camera);
// cout<<m.Rvec<<" "<<m.Tvec<<endl;
cout<<m.Tvec<<endl;
}
cv::imshow("ArUco-Pose-Estimation",im);
if ( (char) cv::waitKey(33) >= 0 )
break;
}
}
MYNTEYE 相机调用 Aruco Library,源代码如下:
#include <opencv2/highgui.hpp>
#include "aruco.h"
#include <ctime>
#include <iomanip>
#include <iostream>
#include "camera.h"
#include "utility.h"
using namespace std;
using namespace mynteye;
int main(int argc,char **argv)
{
aruco::CameraParameters camera;
camera.readFromXMLFile(argv[1]);
aruco::MarkerDetector Detector;
Detector.setDictionary("ARUCO_MIP_36h12");
cv::namedWindow( "ArUco-Pose-Estimation", cv::WINDOW_AUTOSIZE );
std::string name;
name = "MYNTEYE";
cout << "Open Camera: " << name << endl;
Camera cam;
InitParameters params(name);
cam.Open(params);
if (!cam.IsOpened()) {
std::cerr << "Error: Open camera failed" << std::endl;
return 1;
}
ErrorCode code;
cv::Mat img_left;
for (;;)
{
code = cam.Grab();
if (code != ErrorCode::SUCCESS) continue;
if (cam.RetrieveImage(img_left, View::VIEW_LEFT_UNRECTIFIED) == ErrorCode::SUCCESS)
{
auto markers=Detector.detect(img_left,camera,0.102);//0.102 is the marker size
for ( auto m:markers