4.1 Initial Specification
The purpose of this module is to map the two-dimensional coordinates as shown on the image captured to three-dimensional coordinates in real space around the grid. Due to time constraints, the final image calibration using transformation matrices would not be ready for integration within the final code on time. Instead a simpler algorithm was used to determine the real coordinates. This would be based on a single vanishing point model.
The model would make use of two cursors to represent a point in three-dimensional space. There would be an XY cursor to represent where the cursor on the plane, and an XYZ cursor that would be directly above it in real space representing the position above the plane. Upon on event, say right mouse button down, it would switch from moving the XY cursor to moving the XYZ cursor. This cursor would be restrained such that the line between the XYZ cursor and the XY cursor was perpendicular to the x-axis on-screen.
The image of the grid would be represented by the trapezoid in bold on the right. Each of the four corners would be chosen by the user, which would represent the four corners of the grid. The bottom left corner would be the reference point.
The X coordinate would be the across the plane as shown across the screen. The Y coordinate corresponds to the depth into the screen and the Z coordinate represents the height above the plane.
|
Figure 15
| 4.2 Design Process
The algorithm uses the intersections of the left and right lines, defined by the four corners to find the vanishing point. The intersection of the diagonals would represent the centre of the grid.
To map the position, the first step involves is to find the X and Y coordinates. As it is only a single vanishing point, the X coordinate and the Z coordinate could be found through taking proportions, as the change in X and the change in Z remain constant with respect to the change in picture coordinates along a straight line.
i.e.
Note that assuming:
can be done as this mapping model is based on a single vanishing point. If this were to change, the X coordinate would need to be modelled similarly to Y (as shown below) and Z would need to be determined in a different manner.
The change in depth becomes smaller further into the screen. This would require some sort of mathematical model in order to calculate the real Y coordinate. A line would be drawn representing the X coordinate using the vanishing point and the cursor position on the plane. The position resulting from the intersection of this line and the bottom line, A, would then represent (X, 0, 0) in real space. The on-screen distance of this point to the reference point, the bottom left corner, could then be divided by the on-screen distance from the bottom left corner to the bottom right corner and then multiplied by the real length of the grid, which is 500mm. Similarly, the on-screen distance from the XYZ cursor position to the XY cursor position could be divided by the on-screen length of the bottom line and multiplied by the real length of the grid. This can be done since both X and Z should have the same scale under a single vanishing point model. The equations for these are shown below.
To determine the Y coordinate, a logarithmic model was used. This model was in the form of:
(1)
Where Y is the y coordinate, Mm is the magnitude of the line from A to the cursor position and M is the magnitude of the x = constant line, from A to C (i.e. from (x, 0, 0) to (x, 500, 0). Mc is the on-screen distance between A and B. Taking a line parallel to the top and bottom lines and taking it through the intersection of the diagonals, which represent the centre of the grid, can find this. Given that the real positions are known at the bottom line position, the real midpoint and the endpoint, the unknown constants a, k and f can be solved. At the A, Y = 0 and Mm = 0. The resulting equation is shown below.
As a would not be equal to zero, it follows that log (k) = 0. This would suggest k is equal to 1, independent of what the coordinates of the corners of the grid on the picture are.
At C the equation would be:
……(2)
The final equation is found at B:
……(3)
Using the equations 2 and 3, the code can solve for the constants and use equation 1 to map the Y coordinate.
It was also necessary to scale the translations that occurred to the prism. While scaling and rotating the prism would remain the same, translations were calculated in mm, but the input into the drawing VI would be without units. This would require an additional step in the calibration phase to speed the process up.
The additional step involves the user selecting the point where real X and real Y were at 100. Finding what to scale the X translation of the prism by involves an iterative process in which the prism would be translated a certain amount across until the point 1 (which starts at (0, 0) reached the point where the real coordinates are (100, 0, 0). During this process, a counter increments by the translation step each time the process repeats. When the process is finished, the counter is divided by 100 and the result is output as the X scaling factor. This is repeated for finding the Y scaling factor. The X scaling factor multiplied by the real translation in the X direction (in mm) and the Y scaling factor is multiplied by the real translation in the Y direction. Both values are outputted to the drawing algorithm such that the prism is drawn in the correct place.
4.3 Testing Process
Testing consisted of using an image capture before using a digital camera using a digital camera, similar to the image to the right. Knowing that each square on the grid in 100mm in length, testing can be done on the plane. In order to test that it was accurate “outside” the grid. The corners were set inside the actual grid as marked by the green points and the grid length was changed to 300mm instead of 500mm.
The test results below are an example from testing the XY accuracy of the mapping code.
Figure 16
Test Point
|
Expected results
|
Actual Results
|
1
|
(-100, -100)
|
(-100.35, -99.34)
|
2
|
(200, -100)
|
(201.5, -99.34)
|
3
|
(400, -100)
|
(398.34, -99.34)
|
4
|
(100, 100)
|
(100, 101.86)
|
5
|
(300, 100)
|
(300.05, 102.54)
|
6
|
(400, 100)
|
(398.84, 98.42)
|
7
|
(-100, 200)
|
(-100.38, 202.59)
|
8
|
(-100, 400)
|
(-99.32, 401.09)
|
9
|
(100, 400)
|
(100.65, 401.09)
|
10
|
(400, 400)
|
(397.45, 401.09)
|
These values are well within acceptable bounds. Minor errors shown here could be attributable to errors in having cursors and corners not being in exactly the correct position due to the use of pixel coordinates. These pixel coordinates are integers; hence an exact position cannot be selected unless it happens that the pixel coordinates happen to correspond to that position. Other errors are due to the fisheye lens affect, which results in areas closer to the edge of the image being curved. When examined closely, there is distortion in the image above. This is most noticeable in the bottom line, which is not straight.
4.4Final Specification
The current model still makes use of two cursors to represent a point in three-dimensional space. There would be an XY cursor to represent where the cursor on the plane, and an XYZ cursor that would be directly above it in real space representing the position above the plane. However, the code currently takes in a Z factor, which is the difference in picture Y coordinates between the two points. This was due to the fact that the cursor could be restrained more easily if there was only a single variable. If the workspace were to be on a slant, the picture X coordinate of the XYZ cursor position would adjust accordingly such that the line between the XYZ cursor position and the XY cursor position is perpendicular to the X direction.
An additional step was required in the calibration in order to find scaling factors used for translating the prism on screen. This step could have been done without additional user input, but this would involve mapping each iterated point, which would consume more resources of the computer.
4.5 Documentation
Figure 17
The 3d mapping VI will output the real coordinates of a point on the picture.
Inputs
|
Type
|
Description
|
Workspace
|
Cluster of 4 2d integer points
|
This cluster contains the four picture coordinates that make out the four corners of the workspace
|
XY Cursor Position
|
2d integer point
|
The cursor position, which corresponds to the position lying on the plane
|
Plane Length
|
Double
|
The side length of the square. Note that this VI assumes that the workspace is square
|
Z factor
|
Integer
|
The difference in picture y coordinates between the XY cursor position and the XYZ cursor position
|
Outputs
|
Type
|
Description
|
Vanishing Point
|
2d integer point
|
The intersection of the left and right lines
|
Mapped Position
|
3d double point
|
Position with respect to the bottom right corner in mm
|
XYZ Cursor Position
|
2d integer point
|
Effective position of the XYZ cursor position
|
Mean Gradient of Horizontals
|
Double
|
Mean gradient (y/x) of the top and bottom lines. This is used for drawing any y = constant lines later.
|
Figure 18
The FindScale VI will determine factors required to draw correctly the translated position of the prism.
Inputs
|
Type
|
Description
|
Y increment
|
Double
|
The step taken each iteration until the prism point has reached real (0, 100, 0)
|
X increment
|
Double
|
The step taken each iteration until the prism point has reached real (100, 0, 0)
|
Margin for Error
|
Double
|
How far the prism point is from the real point until the point has reached the real coordinates. (Note that this should at least be the size of the increment)
|
Workspace
|
Cluster of 4 2d integer points
|
This cluster contains the four picture coordinates that make out the four corners of the workspace
|
Screen Position
|
Double
|
Dummy variable input to define current prism
|
Viewpoint
|
3d double point
|
Dummy variable input to define current prism
|
Scaling
|
3d double point
|
Scaling of the prism in X, Y and Z
|
Rotation
|
Double
|
The orientation of the initialised prism
|
PictureSizeHeight
|
Integer
|
The height of the picture currently being displayed.
|
Outputs
|
Type
|
Description
|
X Scale
|
Double
|
The factor by which to multiply the real X translation by to input into the drawing VI
|
Y Scale
|
Double
|
The factor by which to multiply the real Y translation by to input into the drawing VI
|
4.5.1 Prism Transformations interaction
This VI was required in order to redraw the representative prism after an operation was performed on the prism. It automatically restrains the prism such that the centre of the prism remains within the prism and limits the length, width and height to input amounts through the use of the coerce function within LabVIEW.
The calibration VI was required in developing code to perform transformations upon the representative prism. It maps the control points to real 3d coordinates. It does this by assuming that the all the control points except for height lie on the plane, and that the height control point is directly above the rotate control point. This is a reasonable assumption as the prism cannot be tilted or lifted above the plane.
Figure 19
Inputs
|
Type
|
Description
|
X Scale
|
Double
|
The factor by which to multiply the real X translation by to input into the drawing VI
|
Cursor Position
|
2d integer point
|
The position of the cursor on the picture
|
Control Points
|
Cluster of 5 2d integer points
|
The position of the control points on the picture
|
Workspace
|
Cluster of 4 2d integer points
|
This cluster contains the four picture coordinates that make out the four corners of the workspace
|
Plane length
|
Double
|
Total length of the grid
|
Image Height
|
Integer
|
Height of the image on screen (as control points are stored with a different coordinate system)
|
Length Limits
|
Cluster of doubles
|
Cluster which contains the maximum and minimum values for length
|
Width Limits
|
Cluster of doubles
|
Cluster which contains the maximum and minimum values for width
|
Height Limits
|
Cluster of doubles
|
Cluster which contains the maximum and minimum values for height
|
Action
|
String
|
Input action for type of transformation to carry out. Options are Rotating, Length, Width, Height and Translate
|
XY Lines Selected
|
Refnum
|
Represents what translation lines have been selected.
0 – None
1 – Translate X only
2 – Translate Y only
3 – Translate X and Y
|
Y Scale
|
Double
|
The factor by which to multiply the real Y translation by to input into the drawing VI
|
Outputs
|
Type
|
Description
|
Relative change in angle
|
Double
|
The change in orientation of the prism. Given in degrees clockwise when viewed from the top
|
Relative Change in Scale
|
Cluster of 3 doubles
|
Changes in the dimensions of the prism. Output is the scaling factor of length, width and height
|
Coerced relative translation
|
3d double point
|
Outputs the translation of the prism. Z will always be zero.
|
Share with your friends: |