pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

來自 cv::solvePnP 的世界坐標中的相機位置

Camera position in world coordinate from cv::solvePnP(來自 cv::solvePnP 的世界坐標中的相機位置)
本文介紹了來自 cv::solvePnP 的世界坐標中的相機位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個校準的相機(內在矩陣和失真系數),我想知道相機的位置,知道圖像中的一些 3d 點及其對應點(2d 點).

I have a calibrated camera (intrinsic matrix and distortion coefficients) and I want to know the camera position knowing some 3d points and their corresponding points in the image (2d points).

我知道 cv::solvePnP 可以幫助我,并且在閱讀了 this 和this 我知道solvePnP rvectvec 的輸出是對象在相機坐標系中的旋轉和平移.

I know that cv::solvePnP could help me, and after reading this and this I understand that I the outputs of solvePnP rvec and tvec are the rotation and translation of the object in camera coordinate system.

所以我需要在世界坐標系中找出相機的旋轉/平移.

So I need to find out the camera rotation/translation in the world coordinate system.

從上面的鏈接看來,代碼很簡單,在 python 中:

From the links above it seems that the code is straightforward, in python:

found,rvec,tvec = cv2.solvePnP(object_3d_points, object_2d_points, camera_matrix, dist_coefs)
rotM = cv2.Rodrigues(rvec)[0]
cameraPosition = -np.matrix(rotM).T * np.matrix(tvec)

我不知道 python/numpy 的東西(我使用的是 C++)但這對我來說沒有多大意義:

I don't know python/numpy stuffs (I'm using C++) but this does not make a lot of sense to me:

  • rvec, tvec 從solvePnP 輸出是3x1 矩陣,3 個元素向量
  • cv2.Rodrigues(rvec) 是一個 3x3 矩陣
  • cv2.Rodrigues(rvec)[0] 是一個 3x1 矩陣,3 個元素向量
  • cameraPosition 是一個 3x1 * 1x3 矩陣乘法,它是一個.. 3x3 矩陣.如何通過簡單的 glTranslatefglRotate 調用在 opengl 中使用它?
  • rvec, tvec output from solvePnP are 3x1 matrix, 3 element vectors
  • cv2.Rodrigues(rvec) is a 3x3 matrix
  • cv2.Rodrigues(rvec)[0] is a 3x1 matrix, 3 element vectors
  • cameraPosition is a 3x1 * 1x3 matrix multiplication that is a.. 3x3 matrix. how can I use this in opengl with simple glTranslatef and glRotate calls?

推薦答案

如果用世界坐標"表示對象坐標",則必須得到 pnp 算法給出的結果的逆變換.

If with "world coordinates" you mean "object coordinates", you have to get the inverse transformation of the result given by the pnp algorithm.

有一個反轉變換矩陣的技巧,它允許您保存反轉操作,這通常很昂貴,并且解釋了 Python 中的代碼.給定一個變換 [R|t],我們有 inv([R|t]) = [R'|-R'*t],其中 R'R 的轉置.因此,您可以編寫代碼(未經測試):

There is a trick to invert transformation matrices that allows you to save the inversion operation, which is usually expensive, and that explains the code in Python. Given a transformation [R|t], we have that inv([R|t]) = [R'|-R'*t], where R' is the transpose of R. So, you can code (not tested):

cv::Mat rvec, tvec;
solvePnP(..., rvec, tvec, ...);
// rvec is 3x1, tvec is 3x1

cv::Mat R;
cv::Rodrigues(rvec, R); // R is 3x3

R = R.t();  // rotation of inverse
tvec = -R * tvec; // translation of inverse

cv::Mat T = cv::Mat::eye(4, 4, R.type()); // T is 4x4
T( cv::Range(0,3), cv::Range(0,3) ) = R * 1; // copies R into T
T( cv::Range(0,3), cv::Range(3,4) ) = tvec * 1; // copies tvec into T

// T is a 4x4 matrix with the pose of the camera in the object frame

更新:稍后,要將 T 與 OpenGL 一起使用,您必須牢記 OpenCV 和 OpenGL 的相機框架軸不同.

Update: Later, to use T with OpenGL you have to keep in mind that the axes of the camera frame differ between OpenCV and OpenGL.

OpenCV 使用計算機視覺中常用的引用:X 指向右側,Y 向下,Z 指向前面(如 這張圖片).OpenGL 中相機的框架是:X 指向右側,Y 向上,Z 指向后(如 這張圖片).因此,您需要繞 X 軸旋轉 180 度.這個旋轉矩陣的公式在維基百科.

OpenCV uses the reference usually used in computer vision: X points to the right, Y down, Z to the front (as in this image). The frame of the camera in OpenGL is: X points to the right, Y up, Z to the back (as in the left hand side of this image). So, you need to apply a rotation around X axis of 180 degrees. The formula of this rotation matrix is in wikipedia.

// T is your 4x4 matrix in the OpenCV frame
cv::Mat RotX = ...; // 4x4 matrix with a 180 deg rotation around X
cv::Mat Tgl = T * RotX; // OpenGL camera in the object frame

這些轉換總是令人困惑,我可能在某些步驟上是錯的,所以請持保留態度.

These transformations are always confusing and I may be wrong at some step, so take this with a grain of salt.

最后,考慮到 OpenCV 中的矩陣以行優先順序存儲在內存中,而 OpenGL 中的矩陣以列優先順序存儲.

Finally, take into account that matrices in OpenCV are stored in row-major order in memory, and OpenGL ones, in column-major order.

這篇關于來自 cv::solvePnP 的世界坐標中的相機位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數)
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
主站蜘蛛池模板: 胜为光纤光缆_光纤跳线_单模尾纤_光纤收发器_ODF光纤配线架厂家直销_北京睿创胜为科技有限公司 - 北京睿创胜为科技有限公司 | 防火门-专业生产甲级不锈钢钢质防火门厂家资质齐全-广东恒磊安防设备有限公司 | 礼堂椅厂家|佛山市艺典家具有限公司 | EFM 022静电场测试仪-套帽式风量计-静电平板监测器-上海民仪电子有限公司 | 锂电池生产厂家-电动自行车航模无人机锂电池定制-世豹新能源 | 德国EA可编程直流电源_电子负载,中国台湾固纬直流电源_交流电源-苏州展文电子科技有限公司 | 精密五金冲压件_深圳五金冲压厂_钣金加工厂_五金模具加工-诚瑞丰科技股份有限公司 | 网站seo优化_seo云优化_搜索引擎seo_启新网络服务中心 | 柔性测斜仪_滑动测斜仪-广州杰芯科技有限公司 | 代理记账_公司起名核名_公司注册_工商注册-睿婕实业有限公司 | 深圳宣传片制作-企业宣传视频制作-产品视频拍摄-产品动画制作-短视频拍摄制作公司 | 物流之家新闻网-最新物流新闻|物流资讯|物流政策|物流网-匡匡奈斯物流科技 | 硫酸钡厂家_高光沉淀硫酸钡价格-河南钡丰化工有限公司 | 压砖机、液压制砖机、静压砖机、环保砖机生产厂家—杜甫机械 | 成都LED显示屏丨室内户外全彩led屏厂家方案报价_四川诺显科技 | 亳州网络公司 - 亳州网站制作 - 亳州网站建设 - 亳州易天科技 | 广州番禺搬家公司_天河黄埔搬家公司_企业工厂搬迁_日式搬家_广州搬家公司_厚道搬迁搬家公司 | 北京易通慧公司从事北京网站优化,北京网络推广、网站建设一站式服务商-北京网站优化公司 | 球盟会·(中国)官方网站| 北京京云律师事务所| 磁力抛光机_磁力研磨机_磁力去毛刺机_精密五金零件抛光设备厂家-冠古科技 | 牛皮纸|牛卡纸|进口牛皮纸|食品级牛皮纸|牛皮纸厂家-伽立实业 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | Safety light curtain|Belt Sway Switches|Pull Rope Switch|ultrasonic flaw detector-Shandong Zhuoxin Machinery Co., Ltd | 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 磁力抛光机_磁力研磨机_磁力去毛刺机-冠古设备厂家|维修|租赁【官网】 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 真空搅拌机-行星搅拌机-双行星动力混合机-广州市番禺区源创化工设备厂 | 免费个人pos机申请办理-移动pos机刷卡-聚合收款码办理 | 不干胶标签-不干胶贴纸-不干胶标签定制-不干胶标签印刷厂-弗雷曼纸业(苏州)有限公司 | 武汉画册印刷厂家-企业画册印刷-画册设计印刷制作-宣传画册印刷公司 - 武汉泽雅印刷厂 | 变色龙云 - 打包app_原生app_在线制作平台_短链接_ip查询 | 无锡网站建设_企业网站定制-网站制作公司-阿凡达网络 | 济南网站建设_济南网站制作_济南网站设计_济南网站建设公司_富库网络旗下模易宝_模板建站 | 模具ERP_模具管理系统_模具mes_模具进度管理_东莞市精纬软件有限公司 | 废气处理设备-工业除尘器-RTO-RCO-蓄热式焚烧炉厂家-江苏天达环保设备有限公司 | 深圳公司注册-工商注册公司-千百顺代理记账公司 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 | 色谱柱-淋洗液罐-巴罗克试剂槽-巴氏吸管-5ml样品瓶-SBS液氮冻存管-上海希言科学仪器有限公司 | 耐腐蚀泵,耐腐蚀真空泵,玻璃钢真空泵-淄博华舜耐腐蚀真空泵有限公司 |