哪种方法是估计拍摄物体尺寸的最佳方法? [英] Which is the best way to estimate measure of photographed things?

查看:14
本文介绍了哪种方法是估计拍摄物体尺寸的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序应该使用欧元硬币作为参考来估计物体的长度(以毫米为单位).这是一个截图示例:

为了得到所拍摄硬币的直径,我首先计算了一个圆通过表格中这 3 个点的方程

x^2 + y^2 + ax + by + c = 0

然后我得到直径

2 * square_root((a/2)^2 + (b/2)^2 -c).

最后我可以执行以下比例得到红笔的长度:

/* length_estimated_pen (mm) : distance_green_pins (points) = real_diameter_coin (mm) : diameter_on_screen (points) */让 distanceGreen:Double = Double(sqrt(pow(self.greenLocationA.center.x - self.greenLocationB.center.x, 2.0) + pow(self.greenLocationA.center.y - self.greenLocationB.center.y, 2.0)))让estimatedMeasure:Double = (distanceGreen * Double(ChosenMeter.moneyDiameter))/直径

ChosenMeter.moneyDiameter 中存储了所选硬币的实际直径作为参考(通过单击下面的 3 个按钮之一).

我需要使用 Double 而不是 CGFloat 因为

[注]

选择此图像是为了强调倾斜,但您应该使用与芯片表面几乎平行的平面图像以避免透视失真.这张图片不是一个很好的例子,立方体离相机比硬币更远......

为此,请参阅不同投影的选择标准

My app is supposed to estimate the length (in millimeters) of an object using euro coins as reference. This is a screenshot example:

To get the diameter of the photographed coin I first calculate the equation of a the circle passing through those 3 points of the form

x^2 + y^2 + ax + by + c = 0

and then I have the diameter by

2 * square_root((a/2)^2 + (b/2)^2 -c).

Finally I can perform the following proportion to get the length of the red pen:

/* length_estimated_pen (mm) : distance_green_pins (points) = real_diameter_coin (mm) : diameter_on_screen (points) */

let distanceGreen:Double = Double(sqrt(pow(self.greenLocationA.center.x - self.greenLocationB.center.x, 2.0) + pow(self.greenLocationA.center.y - self.greenLocationB.center.y, 2.0)))

let estimatedMeasure:Double = (distanceGreen * Double(ChosenMeter.moneyDiameter)) / diameter

where in ChosenMeter.moneyDiameter there is stored the real diameter of the chosen coin as reference (by clicking one of the 3 buttons below).

I need to work with Double instead of CGFloat because this tutorial to solve a system of linear equations (to get a,b,c coefficient of circle equation) works with Double.

The problem is the estimated length of the red pen is always overestimated of more than 10 mm. I guess I should apply a correction factor or complicate the calculus taking into consideration other factors, but which? Can you give me some hints? Any help would be useful to me.

解决方案

  1. find the coin (green bounding box rectangle)

    either manually or by some search for specific color,pattern,hough transform,segmentation... This will limit the area to search for next steps

  2. find the boundary (distinct red edge in color intensity)

    so create a list of points that are the coin boundary (be careful with shadows) just scan for high enough intensity bumps.

  3. compute the circle center

    just average of all border points...

  4. test all boundary points for min/max distance to center

    if the tilt is small then you will have many points with min and max radius so take the middle from them. If the |max-min| is very small then you got no tilt. Linebetween min/max distance point and center gives you black basis vectors.

  5. use black basis vectors to measure

    So select 2 points (red line d) to measure and cast green rays from them parallel to basis vectors. Their intersection will create 2 lines a,b. from that it is easy:

    • d = sqrt((a*a)+(b*b))

    where a,b is the size of the lines in units. you can obtain it like:

    • a_size_unit = a_size_pixel * coin_r_unit / rmax_pixel
    • b_size_unit = b_size_pixel * coin_r_unit / rmin_pixel

[note]

This image was selected to emphasize the skew but you should use images of planes almost paralel to chip surface to avoid perspective distortion. This image is not a good example the cube is more distant to camera then coin ...

To account for this see selection criteria for different projections

这篇关于哪种方法是估计拍摄物体尺寸的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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