两种由旋转矩阵计算欧拉角的办法

算法一:直接法

bool isRotationMatrix(cv::Mat &R)
{
	cv::Mat R_t;
	cv::transpose(R,R_t);
	cv::Mat shouldBeIdentity=R_t*R;
	cv::Mat I = cv::Mat::eye(3,3,shouldBeIdentity.type());
	return norm(I,shouldBeIdentity)< 1e-6;
} 

 void getEulerAngles(cv::Mat matrix)
{

	assert(isRotationMatrix(matrix));
	
	float sy=sqrt(matrix.at<double>(0,0)*matrix.at<double>(0,0)+matrix.at<double>(1,0)*matrix.at<double>(1,0));

	bool singular = sy<1e-6;
	
	if(!singular)
	{
		theta_x=atan2(matrix.at<double>(2,1),matrix.at<double>(2,2));
		//theta_x= theta_x*180.0/3.1416 ;
		theta_y=atan2(-matrix.at<double>(2,0), sy);
		//theta_y= theta_y*180.0/3.1416 ;
		theta_z=atan2(matrix.at<double>(1,0), matrix.at<double>(0,0));
		//theta_z= theta_z*180.0/3.1416 ;
	}
	else
	{
		theta_x=atan2(-matrix.at<double>(1,2), matrix.at<double>(1,1));
		//theta_x= thet
  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值