【问题标题】:how to find real life distance between a camera and a pixel point (x and y coordinates) in an image captured by that camera?如何在该相机拍摄的图像中找到相机与像素点(x 和 y 坐标)之间的真实距离?
【发布时间】:2023-01-18 01:25:39
【问题描述】:

因此,我尝试通过首先考虑将相机放置在地面上并捕获图像来实现逻辑,我首先计算图像上最底部像素沿 y 轴与图像上的 px 和 py 坐标之间的距离,然后我将该距离乘以结果转化为现实生活该图像的像素所覆盖的真实生活距离的值。现在我的任务是重新计算当现在相机被提升到一定高度(与地面成 90 度角)时的距离。现在我如何重新计算新相机位置(即在某个高度)与该相机在新位置拍摄的图像上的点之间的距离?

// point of image along y-axis until ground is visible 
const int groundY = 50;
// real life distance from origin (i.e. from where camera is placed and image bottom most point along y-axis) to point where ground is visible in image 
const int realLifeGroundDist = 200;
const int cameraHeight = 40;

void geoLocation(int ***a, int x, int y, int z, int px, int py){

    double onePixelDistance = realLifeGroundDist/groundY;
    // double distBtwPixels = sqrt(pow(px - ((x/2)-1), 2) + pow(py - (y-1), 2) * 1);

    // Distance formula to calculate dist btw origin and (px,py) pixel
    double distBtwPixels = sqrt(pow(px - (x-1), 2) + pow(py - ((y/2)-1), 2) * 1);
    
    //translating pixel distance to real life distance
    double h = distBtwPixels * onePixelDistance;

    //considering that camera is placed above ground at some height i.e. cameraHeight variable at angle = 90deg and calculating distance btw that point and camera i.e. hypteneuse
    double realLifeDist = sqrt(pow(h, 2) + pow(cameraHeight, 2));
    
    cout<<"Distance between camera and px and py coordinates in image = "<<realLifeDist;
}

根据我的逻辑,realLifeDist 保持放置在新位置的相机捕获的图像上的点之间的距离,即在距地面一定高度处,与地面成 90 度角。我的逻辑正确吗?如果不是,那我该如何计算呢?

【问题讨论】:

  • 这似乎是一道数学题而不是编程题。考虑改为询问math.stackexchange.com。
  • 由于您的视锥通常是金字塔,因此给定 dstBtwPixels 的 realLifeDist 取决于与相机的距离。如果该距离在您的场景中可以改变,则无法计算 realLifeDist。
  • 你有深度信息吗?图像上的一个像素对应于整条射线在 3D 中。

标签: c++ opencv distance


【解决方案1】:

简短的回答是,只要您不知道测量点与相机的距离,就不能。

将图像想象成相机焦点和您要捕捉的物体之间的平面。当光线从物体(红点)射向焦点时,它们与图像平面相交。该交点是对象在图像上的位置。

如您所见,距离相机较远的物体在图像平面上显得更近。 在此草图中,近点与远点具有相同的像素距离。 因此,除非您知道要测量的每个点与相机之间的距离,否则您无法从一张图像中计算出这些点之间的距离。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    • 2011-07-15
    • 1970-01-01
    • 2012-12-09
    • 2018-09-15
    相关资源
    最近更新 更多