创建opencv相机矩阵为iPhone 5 solvepnp [英] create opencv camera matrix for iPhone 5 solvepnp

查看:323
本文介绍了创建opencv相机矩阵为iPhone 5 solvepnp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencv开发一个iPhone的应用程序。我必须使用方法solvePnPRansac:



http://opencv.willowgarage.com/documentation/cpp/camera_calibration_and_3d_reconstruction.html



对于这种方法,我需要提供一个相机矩阵: br>
__ __

| fx 0 cx |

| 0 fy cy |

| _0 0 1 _ |



其中cx和cy表示图像的中心像素位置,fx和fy表示焦点长度,但这是所有的文件说。我不确定应该提供这些焦距。



我选择了另一个网站:



http://docs.opencv.org/ modules / calib3d / doc / camera_calibration_and_3d_reconstruction.html



它显示了opencv如何创建相机矩阵。这里它指出焦距是以像素为单位测量的。



我查过另一个网站:



http://www.velocityreviews.com/forums/t500283-focal-length-in-pixels.html



(约一半)
它说焦距可以使用以下公式从毫米单位转换为像素:fx = fy = focalMM * pixelDensity / 25.4;



我发现的另一个链接声明fx = focalMM * width /(sensorSizeMM);
fy = focalMM * length /(sensorSizeMM);



我不确定这些方程以及如何正确创建这个矩阵。



任何有关如何创建准确的相机矩阵(尤其是iPhone 5)的帮助,建议或链接将非常感谢,



Isaac



ps我认为(fx / fy)或(fy / fx)可能等于相机的宽高比,但这可能是完全错误。



UPDATE: / p>

像素坐标到3D线(opencv)



使用这个链接,我可以知道他们想要fx和fy格式化,因为他们使用它来缩放角度相对到它们与中心的距离。因此,fx和fy可能以像素/(单位长度)为单位,但是im仍然不能确定这个单位长度需要什么,只要x和y彼此成比例,它可以是任意的?

$ b $您可以得到像素焦距的初始(粗略)估计,用焦距除以摄像机传感器像素的宽度(mm) (CCD,CMOS,无论什么)。



您可以从相机手册中获得,或者从以全分辨率拍摄的图像的EXIF头读取。找出后者是更复杂一点:如果你知道它的制造商和型号,你可以查看传感器的规格表,或者你可以只是将其敏感区域的总宽度除以侧。



缺少其他信息,通常可以假定像素为正方形(即fx == fy),并且CCD与透镜的焦轴正交相机矩阵的第一行和第二列中的项为零)。此外,主点(cx,cy)的像素坐标通常难以精确估计,没有仔细设计的校准装置和精心执行的校准程序(这是因为它们本质上与平行于图像的相机平移混淆平面)。因此,最好只是将它们设置为等于图像的几何几何中心,除非您知道图像已经非对称地裁剪。



因此,您最简单的相机型号只有一个未知参数,焦距f = fx = fy。



建议:在您的应用程序中通常更方便地携带水平(或垂直)视场角,而不是焦距以像素为单位。这是因为FOV对图像缩放是不变的。


I am developing an application for the iPhone using opencv. I have to use the method solvePnPRansac:

http://opencv.willowgarage.com/documentation/cpp/camera_calibration_and_3d_reconstruction.html

For this method I need to provide a camera matrix:
__ __
| fx 0 cx |
| 0 fy cy |
|_0 0 1 _|

where cx and cy represent the center pixel positions of the image and fx and fy represent focal lengths, but that is all the documentation says. I am unsure what to provide for these focal lengths. The iPhone 5 has a focal length of 4.1 mm, but I do not think that this value is usable as is.

I checked another website:

http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html

which shows how opencv creates camera matrices. Here it states that focal lengths are measured in pixel units.

I checked another website:

http://www.velocityreviews.com/forums/t500283-focal-length-in-pixels.html

(about half way down) it says that focal length can be converted from units of millimeters to pixels using the equation: fx = fy = focalMM * pixelDensity / 25.4;

Another Link I found states that fx = focalMM * width / (sensorSizeMM); fy = focalMM * length / (sensorSizeMM);

I am unsure about these equations and how to properly create this matrix.

Any help, advice, or links on how to create an accurate camera matrix (especially for the iPhone 5) would be greatly appreciated,

Isaac

p.s. I think that (fx/fy) or (fy/fx) might be equal to the aspect ratio of the camera, but that might be completely wrong.

UPDATE:

Pixel coordinates to 3D line (opencv)

using this link, I can figure out how they want fx and fy to be formatted because they use it to scale angles relative to their distance from the center. therefore, fx and fy are likely in pixels/(unit length) but im still not sure what this unit length needs to be, can it be arbitrary as long as x and y are scaled to each other?

解决方案

You can get an initial (rough) estimate of the focal length in pixel dividing the focal length in mm by the width of a pixel of the camera' sensor (CCD, CMOS, whatever).

You get the former from the camera manual, or read it from the EXIF header of an image taken at full resolution. Finding out the latter is a little more complicated: you may look up on the interwebs the sensor's spec sheet, if you know its manufacturer and model number, or you may just divide the overall width of its sensitive area by the number of pixels on the side.

Absent other information, it's usually safe to assume that the pixels are square (i.e. fx == fy), and that the CCD is orthogonal to the lens's focal axis (i.e. that the term in the first row and second column of the camera matrix is zero). Also, the pixel coordinates of the principal point (cx, cy) are usually hard to estimate accurately without a carefully designed calibration rig, and an as-carefully executed calibration procedure (that's because they are intrinsically confused with the camera translation parallel to the image plane). So it's best to just set them equal to the geometrical geometrical center of the image, unless you know that the image has been cropped asymmetrically.

Therefore, your simplest camera model has only one unknown parameter, the focal length f = fx = fy.

Word of advice: in your application is usually more convenient to carry around the horizontal (or vertical) field-of-view angle, rather than the focal length in pixels. This is because the FOV is invariant to image scaling.

这篇关于创建opencv相机矩阵为iPhone 5 solvepnp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆