手眼标定欧拉角和旋转矩阵相互转化

网上有各种各样的欧拉角和旋转矩阵转换的代码,可是运行发现结果不对,原因是c++的三角函数运算支持的是弧度角,所以在机器人示教器和相机标定的出的内参矩阵角度需要先转化为弧度制,将其存放在数组中进行计算转化,代码如下,已经测试可以运行并且结果正确,放心使用
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

// ConsoleApplication4.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include<iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include<map>
#include <opencv2/opencv.hpp>

#define pi  3.1415926

using namespace cv;
using namespace std;

Mat Robot_eulerAnglesToRotationMatrix(double a[3])
{
	//角度转弧度
	for (int i = 0; i < 3; i++)
		 a[i] = a[i] / 180 * pi;
	
	// Calculate rotation about x axis
	Mat R_x = (Mat_<double>(3, 3) <<
		1, 0, 0,
		0, cos(a[0]), -sin(a[0]),
		0, sin(a[0]), cos(a[0])
		);
	//cout << "R_x" << R_x << endl;
	// Calculate rotation about y axis
	Mat R_y = (Mat_<double>(3, 3) <<
		cos(a[1]), 0, sin(a[1]),
		0, 1, 0,
		-sin(a[1]), 0, cos(a[1])
		);
	//cout << "R_y" << R_y << endl;
	// Calculate rotation about z axis
	Mat R_z = (Mat_<double>(3, 3) <<
		cos(a[2]), -sin(a[2]), 0,
		sin(a[2]), cos(a[2]), 0,
		0, 0, 1
		);
	//cout << "R_z" << R_z<< endl;
	// Combined rotation matrix
	Mat R_R = R_x * R_y *R_z;
	return R_R;
}


int main()
{
	double a[3] = { 30,60,30};
	Mat R1 = (Mat_<double>(3, 3) = Robot_eulerAnglesToRotationMatrix(a));
	cout << R1;

	waitKey(0);
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值