Why we needed it?
When the IR LEDS are tracked, some reasons might cause its loss, like:
1- Getting out of the projection area.
2- Some LEDs turn off.
3- Barriers get into the way of tracking the sensors.
And so the projected image will get distorted, so we needed to estimate the coordinates of the lost IR LEDS.
Actually after implementing this part in our project, the tracking was improved a lot :D.
Scenarios:
We've handled the first 3 scenarios, and ignored when only 1 sensor is available as it's uncommon in most cases.
Algorithm:
We mainly Store the last successful tracking for the 4 LEDs in order to be able to get the coordinates of the lost LEDs.
Of course after reading the algorithm details, you'll find a really important problem that appears "Point Identification" (the new tracked sensors map to which old sensors). We'll discuss this problem and the suggested solution to it in a later article.
1- 1 LED lost, 3 Tracked (Affine)
1- We simply calculate the affine matrix (2*3) that maps "3 Tracked sensors" to "their corresponding old positions".
RotationMatrix2D map = CameraCalibration.GetAffineTransform(src, dst);
src: their corresponding old positions.
dst: 3 Tracked sensors
2- Then take this matrix and multiply it with the corresponding old position of the lost sensor. Which will output the correct estimated position of the sensor.
2- 2 LEDs lost, 2 Tracked (Simplified Affine)
Since there's no ready made fn that makes the simplified affine, so we implemented it ourselves.
We need to calculate 2 dimensions of translation, one degree of rotation, & one degree of scaling.
1- We simply construct 2 vectors, Vector1 (new tracked 2 points), Vector2 (their corresponding old points).
2- Translate scene origin, Translate scene (-x0,-y0)
hint: (x0,y0) id the start point of Vector1
3- Calculate scaling factor, S= |vector2| / |vector1|
hint: |vector2| is its magnitude
4- Calculate rotation angle, Theta= Theta2- Theta1
hint: Theta2= Vector1.y / Vector.x
5- Calculate the matrix that encapsulates the rotation & scaling, and multiply it with the scene
CvInvoke.cv2DRotationMatrix(center, rotation_angle, scale_factor, map.Ptr);
hint: center is the origin of course
6- Translate the scene to (x1,y1)
hint: (x1,y1) is the start point of Vector2