1

你能从 CCD 传感器上的大小推导出显示在手机屏幕上的物理对象图像的大小吗?当您知道物理对象的尺寸、它与相机的距离以及相机的焦距时,您可以确定相机的 CCD 传感器上产生的图像的大小。

正如我在这里所描述的,我计算出手机屏幕的像素比 CCD 传感器的毫米大多少。因此,如果 CCD 上的物体尺寸为x,屏幕比传感器大n倍,则屏幕上物体的尺寸为x * n像素。

我的假设对吗?我测量了 iPhone 4 的n值,但基于以 mm (50x70) 为单位的屏幕尺寸。屏幕是ca。比传感器大 15 倍(根据我的计算)。我从已知距离拍摄了几张已知物体的照片,我从计算中得到的尺寸或多或少等于屏幕上显示的物体图像的尺寸。

但是,我仍然不确定这种方法的正确性。如果你能就此说几句话,我将不胜感激。谢谢你。

4

2 回答 2

2

我不确定所有这些数学是否会让你在任何地方都受益匪浅。在现实世界中(除非您将相机安装在三脚架上并将拍摄对象放置在固定距离内),物体与手机之间的距离可以是任意距离。

如果您有一个已知组成的目标(例如,AR 目标或 QR 码)以已知尺寸(1 平方英寸)打印,您绝对可以根据像素数计算同一焦平面上另一个对象的尺寸。

或者也许在图片中(来自psd的 CC 许可照片):

压扁埃菲尔铁塔

于 2012-08-12T07:07:24.533 回答
1

一种似乎提供足够好的估计的方法 - 在确保输入值的精度的情况下可以证明非常准确,源自这篇文章,它解释了已知传感器的规格(传感器的宽度 - 高度,输出分辨率),和您的焦距,在不考虑缩放因子的情况下,您可以相应地以米或像素为单位计算对象的大小。这是通过计算对象在传感器上占据的像素,然后根据您的需要在实际大小和像素大小之间进行线性转换来实现的。此外,已知物体在现实世界(米)和框架内(像素)的大小,您还可以计算与它的距离。

下面的代码经过测试,它提供了一个近似值 - 与测量值略有偏差 - imo 非常令人满意 - 正如文章所述 -输入的精度至关重要

#Requires 1)Real object size, 2)Distance from object and returns ---> Object_size in pixels
def given_real_get_pixels(Object_width_meters,Object_height_meters,distance):
    
    Object_height_on_sensor_mms=(Focal_length*Object_height_meters)/distance
    #Object_height_on_sensor_mms2
    Object_height_pixels=(Sensor_height_pixels*Object_height_on_sensor_mms)/Sensor_height_mms

    Object_width_on_sensor_mms=(Focal_length*Object_width_meters)/distance
    Object_width_pixels=(Sensor_width_pixels*Object_width_on_sensor_mms)/Sensor_width_mms
    
    print(f'Object_actual_size={Object_width_meters} x {Object_height_meters}(meters) at {distance}(meters) distance coresponds to Object_pixel_size={Object_width_pixels} x {Object_height_pixels}(pixels)')
    return Object_height_pixels,Object_width_pixels  

#Requires 1)distance from object, 2)Object height in pixels and returns ---> Object_size in meters
def given_pixels_get_real(distance,Object_height_pixels,Object_width_pixels):
    Object_height_on_sensor_mms=(Sensor_height_mms*Object_height_pixels)/Sensor_height_pixels    
    Object_height_meters=((distance*Object_height_on_sensor_mms)/Focal_length)

    Object_width_on_sensor_mms=(Sensor_width_mms*Object_width_pixels)/Sensor_width_pixels
    Object_width_meters=((distance*Object_width_on_sensor_mms)/Focal_length)

    print(f'Object_pixel_size={Object_width_pixels} x {Object_height_pixels}(pixels) at {distance}(meters) distance corresponds to Object_actual_size={Object_width_meters} x {Object_height_meters}(meters)')
    return Object_height_meters,Object_width_meters

def given_real_and_pixels_get_distance(Object_width_meters,Object_height_meters,Object_width_pixels,Object_height_pixels):

    Object_height_on_sensor_mms=(Sensor_height_mms*Object_height_pixels)/Sensor_height_pixels
    distance_height=(Focal_length*Object_height_meters)/Object_height_on_sensor_mms

    Object_width_on_sensor_mms=(Sensor_width_mms*Object_width_pixels)/Sensor_width_pixels
    distance_width=(Focal_length*Object_width_meters)/Object_width_on_sensor_mms
        
    print(f'For obtaining an Object_pixel_size={Object_width_pixels} x {Object_height_pixels}(pixels) of an object that has Object_actual_size={Object_width_meters} x {Object_height_meters}(meters), distance must be distance_width = {distance_width}(meters) and distance_height= {distance_height}(meters) and mean_distance(suggested)={(distance_width+distance_height)/2}(meters) ')
    return distance_width,distance_height

#################################################### Define Specifications ######################################################
#Sensor 
Sensor_width_mms=7.410 #mm
Sensor_height_mms=4.980 #mm
Sensor_width_pixels=3088 #pixels
Sensor_height_pixels=2076 #pixels
#Focal length
Focal_length=9.6 #mm

######################################################### Define Parameters ######################################################
distance=125 #0.8 # meters

################################################# GET OBJECT SIZE IN PIXELS ######################################################

Object_width_meters=Object_height_meters=0.001 #meters
Object_height_pixels,Object_width_pixels=given_real_get_pixels(Object_width_meters,Object_height_meters,distance)

################################################# GET OBJECT SIZE IN METERS ######################################################
Object_width_pixels=Object_height_pixels=20
Object_height_meters,Object_width_meters=given_pixels_get_real(distance,Object_height_pixels,Object_width_pixels)

########################################### GET DISTANCE TO OBJECT IN METERS ######################################################
Object_width_meters=0.0005
Object_height_meters=0.001 #meters
Object_width_pixels=10
Object_height_pixels=20
distance_width,distance_height=given_real_and_pixels_get_distance(Object_width_meters,Object_height_meters,Object_width_pixels,Object_height_pixels)

顺便提一下 - 变量的命名可能很麻烦,但并非没有充分的理由.. 稍微解释一下,所有方法都考虑宽度和高度,但每个方法的计算都是独立实现的..

于 2022-02-25T07:53:33.673 回答