JeVois v1.9.0
In this tutorial, we program an Arduino connected to JeVois to make it turn on its LED when a particular object is in sight. This is the JeVois version of the Arduino blink LED tutorial.
Then, let's find pin-out information for our Arduino on the web, for example at https://cdn.sparkfun.com/assets/9/c/3/c/4/523a1765757b7f5c6e8b4567.png and reproduced here:
Wire color | Arduino Pro Micro 32u4 pin |
---|---|
White | RX |
Yellow | TX |
Black | GND (3 GND pins are available) |
Red | VCC (this Arduino has no IOREF pin) |
On the Pro Micro 32u4, there is no LED on the standard pin 13 (this is the LED of other models). However, there are 2 LEDs we can use. One possible LED pin is number 17, labeled 'RX LED'.
Replace all instances of LED_BUILTIN (on recent Arduino software) or of 13 (on older software) in there by 17
Two pages of the main JeVois doc are critical here:
From the doc of one of the object recognition modules, for example, TensorFlowEasy, we read that:
When detections are found with confidence scores above 'thresh', a message containing up to 'top' category:score pairs will be sent per video frame. Exact message format depends on the current serstyle setting and is described in Standardized serial messages formatting. For example, when 'serstyle' is 'Detail', this module sends: DO category:score category:score ... category:score where 'category' is a category name (from 'namefile') and 'score' is the confidence score from 0.0 to 100.0 that this category was recognized. The pairs are in order of decreasing score.
We can further read about the messages in Standardized serial messages formatting
So now we just need to modify the Arduino program to receive and decode these strings, and to turn on the LED when a particular object category is detected.
Our approach for the Arduino code that matches the whole message from JeVois is going to be:
To get started, let's fire up JeVois Inventor, select machine vision module TensorFlowEasy, and turn on serial output messages to both USB and 4-pin in the Console tab. We see object category names as we point JeVois to various things:
A few comments on the code:
strcmp()
returns 0 when the two strings are equal.Compile and upload the code to your Arduino and here you go!
While the whole message match is appropriate for our simple example, it is not scalable to more complex scenarios where messages may contain multiple values that should be decoded and interpreted individually. For example, the more complex messages when serstyle
is Detail take the form
DO category:score category:score ... category:score
and the various categories and scores will vary from message to message. These messages reflect the probabilistic nature of the object recognition deep network, which may output multiple guesses about what it is seeing, each with a confidence score. For example,
DO dog:53.6 cat:42.3
reflects that the deep network is hesitant and thinks it might be looking at a dog (with confidence 53.6), or possibly a cat (with confidence 42.3).
Note that TensorFlowEasy already applies a threshold to confidence scores (see parameter thresh
of the module), so that only categories that score above that threshold are reported.
Let's see how we could parse these messages, so that our Arduino now blinks if any of the categories in the list is a match, i.e., the LED should still turn on if computer_keyboard was the second or third guess.
Our approach for the Arduino code that parses the message from JeVois is going to be:
Set parameter serstyle
to Detail so we get the detailed messages as above and as explained in Standardized serial messages formatting, and turn on serial output messages to both USB and 4-pin in the Console tab. We see object category names as we point JeVois to various things:
serprec
described in Standardized serial messages formatting, you can get more precise floating-point values (e.g., try setpar serprec 3
in the Console of JeVois Inventor). For the code below, we will assume floating point values which could be integers as well.A few comments on the code:
strtok()
is a standard C function, see Arduino docs or other standard C/C++ docs like http://www.cplusplus.com/reference/cstring/strtok/ At this stage, tok
points to the first chunk of characters until the first white space.switch()
statement. We will then advance to the next token on line 76. Remember that strcmp()
returns 0 when both strings are equal.This code should behave like the previous one, but remember that you need serstyle
to be Detail for the messages to be decoded by the Arduino now. The LED should still turn on even if the desired category was second guess, third guess, etc.
Check out these other tutorials. They use similar state machine decoding: