您如何找到给定图像的物体的高度?
这不完全是一个编程问题。我只想知道您对数字图像处理中常见问题的解决方法是什么。
假设您有一张 jpg 格式的几棵树的图像。您将如何找到每棵树的高度?照片是您唯一的输入。
我想知道您不必编码的方法。因此,如果您的答案含糊不清或不符合 DIP 风格,也没关系。
小修正: 高度不必是树的实际高度。高度可以采用任何比例。但应与图片中的所有物体保持一致。
This isn't exactly a programming question exactly. I just want to know what your approach would be to a common problem in Digital image processing.
Let's say you have an image of a few trees in say jpg format. How would you go about finding the heights of each of these trees? The photo is the only input you have.
I want to know the approaches you have not to code. So it doesn't matter if your answers are vague, or non DIP-ish.
Small correction :
The height need not be the actual height of the tree. The height can be taken to any scale. But should be consistent to all objects in the pic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,这是可能的。您所描述的内容涉及整个行业,称为摄影测量
Yes it is possible. What you are describing has an entire industry around it, called Photogrammetry
使用摄影测量从图像中找到物体的大小很简单。
摄影测量是根据照片进行测量的科学。
为此,我们需要知道两件事,
步骤如下:
校准相机
使用openCV来校准相机。可以使用OpenCV calibrate.py工具和源代码中提供的棋盘图案PNG来生成校准矩阵。进行相机标定以找到相机参数。我用网络摄像头从多个角度拍摄了大约十几张棋盘照片(以校准我的网络摄像头)。有关更多详细信息,请查看 openCV 相机校准。
我们将从校准矩阵中得到f_x,f_y,c_x,c_y。
检查您拍摄的照片的详细信息,您将找到照片的原始分辨率(高度X宽度)及其EXIF headers 可以找到焦距值(f)。这些项目可能会因您的相机而异。
每毫米像素
我们需要知道图像传感器上的每毫米像素 (px/mm)。
f_x=f*m_x
f_y=f*m_y
由于每个公式都有两个变量,我们可以求解 m_x 和 m_y。我只是对 f_x 和 f_y 进行平均,得到f_xy。
m=f_xy/focal_length_of_camera
插入图像
插入您需要从中查找图像实际尺寸的图像。您应该知道物体和相机之间的距离。查找图像的尺寸 (height1Xwidth1)
查找以像素为单位的对象大小
确定对象的大小(以像素为单位)。我只是使用距离公式来查找所选线的长度。您可以采用任何其他方法。
以较低分辨率转换 px/mm
pxpermm_in_lower_resolution = (width1*m)/width
图像中对象的大小传感器
size_of_object_in_image_sensor = object_size_in_pixels/(pxpermm_in_lower_resolution)
对象的实际大小
对象的实际大小可以通过以下方式找到上述数据为,
real_size = (dist*size_of_object_in_image_sensor)/focal_length
It is simple to find the size of an object from images using Photogrammetry.
Photogrammetry is the science of making measurements from photographs.
For this we need to know two things,
Following are the steps:
Calibrate the Camera
Use openCV to calibrate the camera.You can use the OpenCV calibrate.py tool and the Chessboard pattern PNG provided in the source code to generate a calibration matrix. Camera calibration is done to find the camera parameters. I took about a dozen of photos of the chessboard photos from many angles as I could with my webcam (to calibrate my webcam). For more details check openCV camera calibration.
We will get f_x,f_y,c_x,c_y from calibration matrix.
Checking the details of the photos you took, you will find the native resolution of the photos(heightXwidth) and in their EXIF headers you can find the focal length value(f). These items may vary depending on your camera.
Pixels per millimeter
We need to know the pixels per millimeter(px/mm) on the image sensor.
f_x=f*m_x
f_y=f*m_y
Since we have two of the variables for each formula we can solve for m_x and m_y.I just averaged f_x and f_y to get f_xy.
m=f_xy/focal_length_of_camera
Insert the image
Insert your image from which you need to find the actual size of image. You should know the distance between object and camera. Find the dimension of the image (height1Xwidth1)
Find the Object size in pixels
Determine the size of object in pixels. I simply use distance formula to find length of a selected line. You can adopt any other method.
Convert px/mm in the lower resolution
pxpermm_in_lower_resolution = (width1*m)/width
Size of object in the image sensor
size_of_object_in_image_sensor = object_size_in_pixels/(pxpermm_in_lower_resolution)
Actual size of object
The actual size of object can be found with the above data as,
real_size = (dist*size_of_object_in_image_sensor)/focal_length
该领域有相当多的计算机视觉研究。假设您不知道相机限制,则必须对场景和相机做出假设,以确定达到比例因子的高度。请注意,如果没有相机限制或图像中的参考高度,则无法区分从远处拍摄的高树和近距离拍摄的矮树之间的区别。 Criminisi 的单视图计量工作是一个很好的开始。
There is a fair amount of computer vision research in this area. Assuming you don't know the camera constraints, you'll have to make assumptions about the scene and camera to determine the heights up to a scale factor. Note that without camera constraints or a reference height in the image it is impossible to tell the difference between a tall tree photographed from a distance or a short tree photographed up close. A great start is the Single View Metrology work by Criminisi.
假设它们的距离都相同,并且全部按比例,您需要找到一个可以保证的单一测量单位。例如,如果照片中有一个人,同样比例,并且您知道他们正好 6 英尺高,您可以使用它作为您的尺寸。然后你拿走它,并数一下有多少堆叠构成了这棵树。例如,如果您需要此人的 3.5 个,则:
为您提供一棵 21 英尺高的树。
如果所有事物都没有单一的参考点,或者如果它们都具有不同的规模,那么您将需要更多的信息,而这些信息是您在现场无法轻松获得的。
Assuming they're all the same distance away, all to scale, you'd want to find a single unit of measurement you can guarantee. For example, if there's a person in the photo, again, same scale, and you know they're exactly 6 feet tall, you use that as your measure. You then take that, and count how many stacked make the tree. For example, if you need 3.5 of this person, then:
gives you a 21 foot tall tree.
Without a single point of reference for everything, or if they're all on different scales, you would need a lot more information than you could easily get without having been there.
我会依赖已知尺寸的物体出现在图片中。比如说一个男人。
或者,我们可以使用 EXIF 数据,根据相机的传感器尺寸、镜头和所使用的焦距,对物体的尺寸进行逆向工程。这又取决于角度。当相机垂直于拍摄对象时,我们应该得到最准确的结果。
I would rely on an object of known dimensions to be present in the picture. For instance, a man.
Or perhaps, we could use the EXIF data to reverse engineer the size of the object based on the camera's sensor dimensions, the lens and the focal length used. This again depends on the angle. We should be getting most accurate results when the camera has been held perpendicular to the subject.
如果您的图像是 3*3 并且您想找出图像的大小(即 3x3..so 3x3 = 9),现在我们有 8 个像素,从 0 到 8。所以 9/8=(___)kb。
如果你想找到以 MB 为单位的图像大小,就像上面的例子一样,只需这样做 (9/8)/(1024)=(----)MB ..
这样你就会得到以 Mb 为单位的结果。
If your image is 3*3 and you want to find out the size of image (i.e 3x3..so 3x3 = 9) now we have 8 pixels starting from 0 up to 8. So 9/8=(___)kb.
If you want to find the size of image in MB, like doing above example, just do like that (9/8)/(1024)=(----)MB..
So you will get the result in Mb.