What is the best way to evaluate the measure of photographed things?

My application should evaluate the length (in millimeters) of an object using euro coins as a reference. This is an example screenshot:

enter image description here

To get the diameter of the photographed coin, I first calculated the equation of a circle passing through these 3 points of the form

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

and then I have a diameter on

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

Finally, I can do 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 the actual diameter of the selected coin is stored as a link (by clicking one of the 3 buttons below).

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

The problem , the estimated length of the red pen is always overestimated more than 10 mm. I think I should apply a correction factor or complicate the calculation taking into account other factors, but what? Can you give me some advice? Any help would be helpful to me.

+4
source share
1 answer
  • find the coin ( green rectangle rectangle)

    either manually or by searching for a specific color, pattern, hough transform, segmentation ... This will limit the scope for searching for the next steps

  • find border (excellent red border for color intensity)

    so create a list of points that are the border of the coins (be careful with the shadows), just scan for high enough intensities.

  • calculate the center of the circle

    just the average of all the boundary points ...

  • check all boundary points for min/max distance to center

    if the slope is small, then you will have many points with a minimum and maximum radius, so take the middle of them. If |max-min| very small, then you do not have a slope. Linebetween min / max distance point and center give you the basic black vectors.

  • use black base vectors to measure

    So, select 2 points ( red line d) to measure and distinguish the rays from them parallel to the base vectors. Their intersection will create lines 2 a,b . from this easy:

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

    where a,b - the size of the lines in units. You can get it as:

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

coin

[note]

This image was chosen to emphasize the skew, but you should use images of planes that are almost parallel to the surface of the crystal to avoid distortion of perspective. This image is not a good example of the fact that the cube is more distant from the camera than the coin ...

To account for this, see selection criteria for different forecasts.

+3
source

Source: https://habr.com/ru/post/1013095/


All Articles