This is the bulk of the work for the distance calculator and does everything up to relating the object coordinate locations with real world units, and it does not yet display lengths/ angles between points. @cgregory52 please check my math.
Creating the model:
Two new value objects were added to represent data used by the tool. AxisValue and PointValue. The points within these objects are origined at the center of the screen and are the percentage from the middle of the screen to the edges. This allows points to be placed on the image and reconstructed for different scales of the working image.
Creating the view:
A new ShapeNode interface and ShapeScene class have been created to allow moving objects on the screen. ShapeNode has two implementations.. AxisNode to represent a AxisValue and LabeledNode to represent a PointValue. ShapeNode objects are a hierarchy of nodes, allowing further development of complicated objects to place on the scene.
Creating the calculator:
Most of the math is discussed in the issue #297 , however, I have placed how the logic works as a comment in the code. The math behind this algorithm uses solvePNP to calculate potential ground planes in the scene. The traditional way to do this is to have a known length in the scene which you can represent in object coordinates. These object coordinates are paired with image coordinates and allow the solvePNP method to figure out a transformation from the object coordinates to the image plane. That equation looks like this:
s * Pc = M * (R * Pw + T)
s = scalar
Pc = imagePoint
Pw = objectPoint
M = intrinsicMatrix
R = rotationMatrix
T = translationVector
Without a known length however we cannot correctly guess the scale between the x and y values on a surface.
The trick to finding out the missing size is guess and check. If we guess too small or too large a size then the z axis will not properly translate from image-object or vice-versa. Consider the case where two sides should be equal. Only that value will result in a z-axis which is valid.
Test if the point is on the z axis:
Reverse standard mapping to figure out a mapping of image to object coordinates:
Pw = s * inv(R) * inv(M) * Pc - inv(R) * T
Pw = s * a - b
When a pixel is projected into object space it creates a ray in the scene. This leaves a linear equation of:
The value of x which is the closest to being able to satisfy this equation will be considered the
correct value of the object space coordinate moving forward.
Using this value to find distances:
Calculate the image to object coordinate mapping by assuming that the point is on the ground plane. This constrains the ray equation to:
This is the bulk of the work for the distance calculator and does everything up to relating the object coordinate locations with real world units, and it does not yet display lengths/ angles between points. @cgregory52 please check my math.
Creating the model: Two new value objects were added to represent data used by the tool.
AxisValue
andPointValue
. The points within these objects are origined at the center of the screen and are the percentage from the middle of the screen to the edges. This allows points to be placed on the image and reconstructed for different scales of the working image.Creating the view: A new
ShapeNode
interface andShapeScene
class have been created to allow moving objects on the screen.ShapeNode
has two implementations..AxisNode
to represent aAxisValue
andLabeledNode
to represent aPointValue
.ShapeNode
objects are a hierarchy of nodes, allowing further development of complicated objects to place on the scene.Creating the calculator: Most of the math is discussed in the issue #297 , however, I have placed how the logic works as a comment in the code. The math behind this algorithm uses solvePNP to calculate potential ground planes in the scene. The traditional way to do this is to have a known length in the scene which you can represent in object coordinates. These object coordinates are paired with image coordinates and allow the solvePNP method to figure out a transformation from the object coordinates to the image plane. That equation looks like this:
Without a known length however we cannot correctly guess the scale between the x and y values on a surface.
The trick to finding out the missing size is guess and check. If we guess too small or too large a size then the z axis will not properly translate from image-object or vice-versa. Consider the case where two sides should be equal. Only that value will result in a z-axis which is valid.
Test if the point is on the z axis: Reverse standard mapping to figure out a mapping of image to object coordinates:
When a pixel is projected into object space it creates a ray in the scene. This leaves a linear equation of:
We know that this ray must intersect at some point with the z-axis ray in object space. This means that we can constrain the system to the following:
This leaves the system with two solutions for s:
For this equation to be solvable it means that:
The value of x which is the closest to being able to satisfy this equation will be considered the correct value of the object space coordinate moving forward.
Using this value to find distances: Calculate the image to object coordinate mapping by assuming that the point is on the ground plane. This constrains the ray equation to:
This leaves us with a single solution for s:
Plug this value back into the first equation to solve for x and y