我有一个已知尺寸和位置在墙上的矩形目标,以及机器人上的移动摄像头.当机器人在房间里行驶时,我需要找到目标并计算摄像机的位置及其姿势.另外,使用伺服系统可以改变摄像机的高度和方位角.我能够使用OpenCV定位目标,但我仍然模糊计算摄像机的位置(实际上,我的额头上有一个平坦的位置,因为上周我的头撞在墙上).这是我在做的事情:
我已经阅读了OpenCV书籍,但我想我只是遗漏了一些如何使用投影点,旋转和平移向量来计算相机的世界坐标及其姿势(我不是数学专家): - (
2013-04-02根据"morynicz"的建议,我写了这个简单的独立程序.
#include <Windows.h>
#include "opencv\cv.h"
using namespace cv;
int main (int argc, char** argv)
{
const char *calibration_filename = argc >= 2 ? argv [1] : "M1011_camera.xml";
FileStorage camera_data (calibration_filename, FileStorage::READ);
Mat camera_intrinsics, distortion;
vector<Point3d> world_coords;
vector<Point2d> pixel_coords;
Mat rotation_vector, translation_vector, rotation_matrix, inverted_rotation_matrix, cw_translate;
Mat cw_transform = cv::Mat::eye (4, 4, CV_64FC1);
// Read camera data
camera_data ["camera_matrix"] >> camera_intrinsics;
camera_data ["distortion_coefficients"] >> distortion;
camera_data.release ();
// Target rectangle coordinates in feet …Run Code Online (Sandbox Code Playgroud)