V-Function is a series of **visual recognition** functional firmware developed by the M5Stack team for V series devices. Based on different functional firmware (target trace, motion detection, etc.), users can quickly build visual recognition functions. This tutorial will show you how to burn firmware into your device and call it through UIFlow graphical programming.
?>Note: For Linux users, please switch to the decompressed file path and run `./M5Burner` in the terminal to run the application.
>Select the device as M5StickV/UnitV in the device bar on the left, and select the corresponding function firmware according to the usage requirements to download. Connect the device to the computer through the data cable, select the corresponding port, and click Burn to start burning.
> The M5StickV/UnitV with the function firmware burned will be used as a slave device in the form of Unit, so users need to use other M5 host devices to interact with it. For the basic usage and operation of UIFlow of other master products, please visit the corresponding product documentation page to obtain it.
>Visit https://flow.m5stack.com/ to enter UIFlow. Click the Unit add button in the function panel on the right and select UnitV extension to add it. When adding, please configure according to the actual port used. Click ok to add.
>After the addition is complete, you can find the included function block in the Unit option in the function block menu. Drag and drop it to the programming area on the right to use it. For more details, please see the case program below.
>After using the slave device (M5StickV/UnitV) to connect to the main control, if there is a situation where the main control end cannot obtain data, please restart M5StickV/UnitV. Wait for the firmware to start successfully and try to connect again.
## Example
### Motion detect
>Detect the change of the picture on the view, and judge whether there is motion of the target in the detection area.
+ Set the change rate threshold: When the pixel whose change is less than this value is not considered to have changed, its change is not included in the total rate of difference.
-`Set detect mode`
+ dynamic: Dynamic detection mode, after configuration will continuous to take pictures, compare the changes between the two frames before and after
+ static:In static detection mode, a reference picture will be taken and saved after execution, and subsequent pictures will be continuously compared with this picture. If you need to take a new reference picture, you need to switch back to the motion detection mode first, and then perform the static detection mode setting again.
-`Get rate of difference`
+ rate of difference : Detect the change amount of changed pixels between two frames before and after comparison. Assuming that 2 pixels have changed, pixel A has changed by 27, and pixel B has changed by 10, then the change value is 27+10=37. The sum of the differences of the R.G.B components of the two pixels is the amount of change.
-`Get max difference`
+ max difference: the amount of change in the pixel that changes most drastically.
+ Gets the number of bounding boxes generated by pixel changes.
-`Get number x box detail`
+ The details of the x bounding box are returned as a list, including the number of changed pixels in the bounding box, the X-axis coordinates of the bounding box, the Y-axis coordinates of the bounding box, the width and height of the bounding box.
>Program case: Enable the dynamic detection mode, and determine whether there is movement of the target in the screen by reading the maximum change rate value of the screen. When the change rate value is greater than the expected value, "Moved" is displayed, otherwise "Not Move" is displayed. The screen displays the current maximum rate of change value.
+ Set the box to select the target. The parameter is the position of the current target on the image (select the target with significant color characteristics if possible).
+ The coordinate on the image of the target selected by the read box. The return value is in the form of a list, which contains the coordinate x and y of the top left corner of the box, as well as the width and height of the box.
>Program case: Set the frame selection target by pressing button A, read the target coordinate value, used to control the movement of rectangular elements on the screen, and simulate the display of the target's trajectory
>Set the LAB color threshold, track the target that meets the threshold in the screen, and obtain the position information of the target object in the screen in real time.
+ Gets the details of the bounding, including the number of changing pixels in the bounding box, the bounding x-coordinate, the bounding y-coordinate, the bounding width, and the bounding height.
> Click the object you want to use for color recognition, record the LAB value generated below, and configure it for use in UIFlow. Supplement: Drag the interval bar of the LAB value, which can be used to customize the LAB value.
>Program case: Set the LAB threshold for recognition, realize the color tracking effect, and obtain the coordinate data of the tracked object in the screen, and the number of pixels that meet the threshold.
+ Read the face detail data of the specified number, and the return format is a list, which includes the face frame selection coordinates, length, and placement confidence rate
>Program case: Read the face recognition results in the screen and the confidence rate.
>Identify the Datamatrix code in the screen, and return the recognition result, the code rotation angle, and the coordinate data. use firmware`Find code`.
>Program case: The case can reflect the rotation degree of APRILTAG code, the number of moving units, and the detailed position information of APRILTAG code.
>The above multiple identification code functions are all implemented using the same firmware `Find Code`. Users can configure mode switching by sending the JSON data below.
>Detect the tag card in the screen and return to the binary sequence. Note: Only the fixed label card format is recognized, please refer to the picture below
"p0x": 113, // p0x ~ p3y: TAG Coordinates of 4 vertices
"p0y": 77,
"p1x": 211,
"p1y": 65,
"p2x": 230,
"p2y": 156,
"p3x": 127,
"p3y": 170,
"rotation": 8, // Relative rotation angle of TAG
"rows": 8, // Number of TAG lines (this value does not include positioning boxes)
"columns": 8, // The number of TAG columns (this value does not include the positioning box)
"size": 64, // TAG data length of the actual content, the value = the number of rows of the content * the number of columns of the content = (rows) * (columns)
"code": "0x003C42425A424200", // The content binary code of uint64_t type, the maximum encoding of this key is 64-bit (8 x 8) TAG
"binstr": "0000000000111100010000100100001001011010010000100100001000000000" //The string form of binary data, this key value can encode TAG of any length and width
}
}
```
### Line Tracker
>Detect the specified color line in the screen and return the offset angle.
-`Set color by L-min L-max A-min A-max B-min B-max`
+ Set the LAB threshold for tracking (the color value of the LAB color space, colors outside this range will be filtered)
-`Set line area weight0 weight1 weight2`
+ Set the weight of the line area: the three weights correspond to the contribution of the three areas in the figure to the angle. For example, if the value of weight_2 is set larger, the angle will change more drastically when turning.
>Refer to the method of using the LAB color picking tool in the `color tracking` function above, shoot the lines and scenes that need to be tracked, and record the LAB values generated below, and configure and use them in UIFlow.