NXT-Spy – Fixes on the flag coordinates processing and of the output of the coloured ball processing

In order to get the coordinates of the flag from the flag processing library (zxing), we are using a function called getResultPoints() on the result object outputted. The problem is that this function only outputs three points, from now on I supposed it was the top left, top right and bottom left coordinates of the flag, but actually, I just figured that it is more complicated than that.

In fact, the flag processing only provides us the coordinates of the “target style” points we can find on any QR code in a random order. The problem is that to be able to get precisely the flag position, we need first to find the coordinate of the fourth corner of the flag and then to get the smallest rectangle in which all the points can fit corresponding to the flag’s position.
That’s why today I added to the flag processing process a function that calculates and draw the two rectangle involved in the process as shown on the image below:

Assuming we have a triangle ABC made from the three QR points placed randomly (their order can change if we rotate the flag), the first step is to find the biggest side of the triangle (AC in this example), we then find its centre (D in this example). We then calculate the symmetric point of B centred on D (E in this example), it is the fourth point we were looking for and we can now calculate the coordinates of the red rectangle quite easily thanks to the java.awt.Rectangle add function (a function that adds points to a Rectangle object and outputs the smallest rectangle that includes all the points passed to it).

Now, the flag processing is more accurate and works for any inclination of the flag, an other good thing is that now it outputs a java.awt.Rectangle instead of an array of points.
After done all that on the flag processing, I thought that it could be interesting if the coloured ball processing could also output a Rectangle object instead of ukdave’s BoundingBox object. BoundingBox and java.awt.Rectangle being quite similar, I quickly did the modifications in the coloured ball processing process code and so now everything is more standard: the two image processing coordinates output are a java.awt.Rectangle object.

NXT-Spy – Testing the QR code (flag) processing

For the QR code processing, I implemented the XZing library quite quickly thanks to the documentation of it. And I printed the QR codes for the letters B and R in full size on two A4 sheets.

At first, I didn’t have really good results : the barcode were decoded only when the camera was at a distance of 0.5m and with a good luminosity.

After some thought, I realized that the very low resolution I used so far was probably not big enough to allow ZXing to decode the complex QR code precisely.

So I almost doubled it to 320 x 240 and got way better results : QR codes are now decoded from as far as 1.5m and with and angle of something like 30 degrees with the flag. Obviously, I have a lower frame-rate, but it is still acceptable as long as we are working in optimal conditions (a powerful Linksys router with no encryption key).

Supervisor’s comment:

I am impressed that you are able to read the ‘flags’ from such a distance as 1.5 m and also from an acute angle.
Its now a case of getting all the bits and pieces to talk to each other in a coherent manner that allows the balls to be sorted!
Next week is the review with Kevin, so remember to bring i  the robot and show him those buts that already work and those bits that are still under development.