日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

opencv使用cv::solvePnP中输入参数问题

發布時間:2023/12/13 综合教程 29 生活家
生活随笔 收集整理的這篇文章主要介紹了 opencv使用cv::solvePnP中输入参数问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在opencv3.3文檔中的Camera Calibration and 3D Reconstruction

bool cv::solvePnP	(	InputArray 	objectPoints,
InputArray 	imagePoints,
InputArray 	cameraMatrix,
InputArray 	distCoeffs,
OutputArray 	rvec,
OutputArray 	tvec,
bool 	useExtrinsicGuess = false,
int 	flags = SOLVEPNP_ITERATIVE 
)	
bool cv::solvePnPRansac	(	InputArray 	objectPoints,
InputArray 	imagePoints,
InputArray 	cameraMatrix,
InputArray 	distCoeffs,
OutputArray 	rvec,
OutputArray 	tvec,
bool 	useExtrinsicGuess = false,
int 	iterationsCount = 100,
float 	reprojectionError = 8.0,
double 	confidence = 0.99,
OutputArray 	inliers = noArray(),
int 	flags = SOLVEPNP_ITERATIVE 
)	

在文檔中,對于objectPoints和imagePoints的類型要求是:

objectPoints: Array of object points in the object coordinate space, Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points. vector

如果使用Nx3 1-channel 和Nx2 1-channel作為輸入, 那么編譯會出現以下錯誤

CV_IS_MAT(_src) && CV_IS_MAT(_dst) && (_src->rows == 1 || _src->cols == 1) && (_dst->rows == 1 || _dst->cols == 1) && _src->cols + _src->rows - 1 == _dst->rows + _dst->cols - 1 && (CV_MAT_TYPE(_src->type) == CV_32FC2 || CV_MAT_TYPE(_src->type) == CV_64FC2) && (CV_MAT_TYPE(_dst->type) == CV_32FC2 || CV_MAT_TYPE(_dst->type) == CV_64FC2)

從錯誤中可知:

(_src->rows == 1 || _src->cols == 1) && (_dst->rows == 1 || _dst->cols == 1)

所以需要將數據reshape成多通道的形式:

objectPoints = objectPoints.reshape(4, 1, 3);
imagePoints = imagePoints.reshape(4, 1, 2);

或者使用std::vectorcv::Point2f和std::vectorcv::Point3f等形式作為輸入參數

using namespace std;
using namespace cv;

vector<Point2f> objectPoints = { Point2f(433,50),Point2f(512,109),Point2f(425,109),Point2f(362,106) };
vector<Point3f> imagePoints = { Point3f(0,0,0),Point3f(6.5,0,0),Point3f(0,0,6.5),Point3f(0,6.5,0) };

參考

Camera Calibration and 3D Reconstruction
solvePnP object_points / image_points shape?
[OpenCV Error: Assertion failed in undistort.cpp at line 293 [closed]](

總結

以上是生活随笔為你收集整理的opencv使用cv::solvePnP中输入参数问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。