Control the distance calculator from the distance calculator view #318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
AxisValueandPointValue. 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
ShapeNodeinterface andShapeSceneclass have been created to allow moving objects on the screen.ShapeNodehas two implementations..AxisNodeto represent aAxisValueandLabeledNodeto represent aPointValue.ShapeNodeobjects 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