OpenCV:计算摄像机和像素之间的角度 [英] OpenCV: Calculate angle between camera and pixel

查看:684
本文介绍了OpenCV:计算摄像机和像素之间的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何计算照片中某些像素相对于我使用的网络摄像头的角度。我是新的这种事情,我使用网络摄像头。基本上,我拍照,处理它,我最终得到一个像素值的图像,这是我正在寻找。然后我需要以某种方式将该像素值转换为一些有意义的数量---我需要找到一个通过像素和相机的线/向量。我不需要大小,只是阶段。



如何做呢?是否需要相机校准?



感谢

解决方案

您不需要知道到物体的距离,只需要知道相机的分辨率和视角。



计算角度只需简单的线性插值。例如,让我们假设一个分辨率为1920x1080的相机,在对角线上覆盖45度的视角。



在这种情况下,sqrt(1920 2 + 1080 2 )沿对角线给出2292.19像素。这意味着每个像素代表45 / 2292.19 = .0153994度。因此,计算距离中心的距离(以像素为单位),乘以.0153994,你有它​​的从中心的角度(对于那个相机 - 对于你的,你显然必须使用它的分辨率和视角)。



当然,这有点近似 - 其精度将取决于镜头有多大的失真。使用变焦镜头(特别是较宽的角度),你通常可以指望它相当高。使用固定焦距镜头(特别是如果它不覆盖大于90度的角度),它通常会很低。



如果你想提高精度,您可以从相机视角内部的直线拍摄平直矩形的图片开始,然后基于与所得到的图片中的完全直线的偏差计算失真。如果你使用极广角镜头,这可能是必不可少的。使用覆盖较窄视角的透镜(特别地,如已经提到的,如果其具有固定焦距),很少可能是值得的(这种透镜通常仅具有一小部分的失真百分比)。

$ b $ 。

I'd like to know how I can go about calculating the angle of some pixel in a photo relative to the webcam that I'm using. I'm new to this sort of thing and I'm using a webcam. Essentially, I take a photo, process it, and I end up with a pixel value in the image that is what I'm looking for. I then need to somehow turn that pixel value into some meaningful quantity---I need to find a line/vector that passes through the pixel and the camera. I don't need magnitude, just phase.

How does one go about doing this? Is camera calibration necessary? I've been reading a bit about it but am unsure.

Thanks

解决方案

You don't need to know the distance to the object, only the resolution and angle of view of the camera.

Computing the angle requires only simple linear interpolation. For example, let's assume a camera with a resolution of 1920x1080 that covers a 45 degree angle of view across the diagonal.

In this case, sqrt(19202 + 10802) gives 2292.19 pixels along the diagonal. That means each pixel represents 45/2292.19 = .0153994 degrees.

So, compute the distance from the center (in pixels), multiply by .0153994, and you have its angle from the center (for that camera -- for yours, you'll obviously have to use its resolution and angle of view).

Of course, this is somewhat approximate -- its accuracy will depend on how much distortion the lens has. With a zoom lens (especially wider angle) you can generally count on that being fairly high. With a fixed focal length lens (especially if it doesn't cover an angle wider than 90 degrees or so) it'll usually be pretty low.

If you want to improve accuracy, you can start by taking a picture of a flat rectangle with straight lines just inside the angle of view of the camera, then compute the distortion based on the deviation from perfectly straight in the resulting picture. If you're working with an extremely wide angle lens, this may be nearly essential. With a lens covering a narrower angle of view (especially, as already mentioned, if it's fixed focal length) it's rarely likely to be worthwhile (such lenses often have only a fraction of a percent of distortion).

这篇关于OpenCV:计算摄像机和像素之间的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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