简体   繁体   English

使用 opencv/c++ 将像素转换为 mm --> 两点之间的距离

[英]Convert pixels to mm with opencv/c++ --> Distance between two points

I have two points p1(x1, y1) and p2(x2, y2).我有两个点 p1(x1, y1) 和 p2(x2, y2)。 Both are centers of two circles in a 2D plan.两者都是二维平面图中两个圆的中心。 The two circles are detected automatically in a picture taken by the user with his smartphone.在用户用智能手机拍摄的照片中会自动检测到这两个圆圈。

For some reasons I want to measure the distance (in meters) between p1 and p2.由于某些原因,我想测量 p1 和 p2 之间的距离(以米为单位)。

I absolutely have no clue of how I can do it.我完全不知道我该怎么做。 I did have a look at calib3D module but I don't think I found anything useful.我确实看过 calib3D 模块,但我认为我没有发现任何有用的东西。

The distance between the camera and the circles may vary and is nerver constant, I think this a parameter we could pay attention to?相机和圆圈之间的距离可能会有所不同,并且是恒定的,我认为这是我们可以关注的参数? For the calculation of the distance of the two centers.用于计算两个中心的距离。

Is there a particular way to do such a thing?有没有一种特殊的方法来做这样的事情? If you have any method that could help me, I'd be grateful.如果您有任何方法可以帮助我,我将不胜感激。

Thanks, have a nice day.谢谢,祝你有美好的一天。

Hugo雨果

you need to use an Augmented Reality toolkit.您需要使用增强现实工具包。 nothing less will solve the problem, unless your problem has constraints that make it simpler than stated.没有什么能解决问题,除非你的问题有限制,使它比说的更简单。

such toolkits are available for Apple and Android mobile platforms.此类工具包可用于 Apple 和 Android 移动平台。

it makes no sense for you to try to implement the core of Augmented Reality yourself.你自己尝试实现增强现实的核心是没有意义的。 some understanding of the theory does help in using a toolkit.对该理论的一些理解确实有助于使用工具包。

Ok so,好吧,

Here are the steps to A solution:以下是解决方案的步骤:

I) First make an orthonormal plan. I) 首先做一个正交规划。

I needed two build up an orthonormal plan in which I will calculate the distance between the 2 points.我需要两个建立一个正交计划,我将在其中计算 2 个点之间的距离。

I need to know the distance in centimeters, I have a picture in pixels so I need to know how many centimeters is a pixel.我需要知道以厘米为单位的距离,我有一张以像素为单位的图片,所以我需要知道一个像素是多少厘米。

In my case, the picture is 2498 x 1570 pixels.在我的例子中,图片是 2498 x 1570 像素。 When I measure with a ruler on the sheet taking the good corners:当我用尺子在纸上测量好的角落时:

2498 px = 18.2 centimeters and 1570 px = 11.4 centimeters. 2498 像素 = 18.2 厘米和 1570 像素 = 11.4 厘米。

With these datas we know that 1 px =~ 0.0073 centimeters.通过这些数据,我们知道 1 px =~ 0.0073 厘米。 (18.2 / 2498 =~ 0.0073). (18.2 / 2498 =~ 0.0073)。 (11.4 / 1570 =~ 0.0073) (11.4 / 1570 =~ 0.0073)

II) Distance formula in an orthonormal plan II) 正交平面中的距离公式

double Operation::distanceBetween2Points(Point A, Point B){

    double coeff = 0.0073;
    double diffx = (B.x - A.x) * coeff;
    double diffy = (B.y - A.y) * coeff;

    return sqrt(pow(diffx, 2) + pow(diffy,2));
}

I've found a distance equal to 0.61005 centimeters which matches the reality (= 0.6 cms).我发现与现实相符的距离等于 0.61005 厘米(= 0.6 厘米)。

I ran several tests, it works every times, matching the reality.我进行了几次测试,它每次都有效,与现实相符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM