Opencv中使用c++的矩阵乘法

matrix multiplication in Opencv using c++

本文关键字:c++ Opencv      更新时间:2023-10-16
大家好,我是C++和Opencv的新手。请帮我解决这个问题。

我有一个函数(cv::aruco::estimatePoseSingleMarkers(markerCorners,markerLength,camMatrix,distCoeffs,rvec,tvecs(;这给出了马克笔w.r.t相机的姿势。我使用for循环从函数中打印出tvecs的值。

tvecs:-0.02402480.01611650.052999]

当我打印tvecs的大小时,它说大小是1。但我认为它ś1x3。

我的要求是执行上述tvces和大小为[3x3]的矩阵的矩阵乘法。我该怎么做?以下是一段代码:

// Get frame and convert to OpenCV Mat
int openCVDataType=CV_8UC3;
cv::Mat image(cv::Size(pRequest->imageWidth.read(),pRequest->imageHeight.read()),openCVDataType,pRequest->imageData.read(),pRequest->imageLinePitch.read() );
//Undistort
cv::remap(image, imageUndist, map1, map2, CV_INTER_LINEAR);
//ArUco detection
cv::aruco::detectMarkers(imageUndist,dictionary,markerCorners,markerIds,detectorParams,rejectedCandidates);
if(markerIds.size() > 0) {
cv::aruco::estimatePoseSingleMarkers(markerCorners, markerLength, camMatrix, distCoeffs, rvecs,tvecs);

for(unsigned int d = 0;d<markerIds.size();d++) {
cout<<"tvecsss: "<<tvecs[d]<<endl;
cout<<"tvecs: "<<tvecs[d].t()<<endl;
cv::Mat rotMat;               
cv::Rodrigues(rvecs[d],rotMat);
rotMat = rotMat.t();
cout<<"rotMat: "<<rotMat<<endl;
cout<<"translation: "<<-tvecs[d]*rotMat<<endl;
}

当我乘以tvecs[d]*rotMat时,出现了一个错误。这就是错误:

mat.inl.hpp:1274: error: (-215:Assertion failed) data && dims <= 2 && 
(rows == 1 || cols == 1) && rows + cols - 1 == n && channels() == 1 in 
function 'operator cv::Vec<_Tp, m>'

您需要更改以下内容:

-tvecs[d]*rotMat

插入此:

rotMat*-tvecs[d]

Tvec是3x1矩阵,rotMat是3x3矩阵