Object detection based on YOLO Fastest and NanoDet. Supports V-Training.
Please switch the function to Object Recognition
// Select the parameter "yolo_20class" to switch to this function
{
"function": "Object Recognition",
"args": ["yolo_20class"]
}
// Select the parameter "nanodet_80class" to switch to this function
{
"function": "Object Recognition",
"args": ["nanodet_80class"]
}
Built-in models support recognizing the following objects
yolo_20class: [
"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog",
"horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"
]
nanodet_80class: [
"person","bicycle","car","motorbike","aeroplane","bus","train","truck","boat","traffic light",
"fire hydrant","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow",
"elephant","bear","zebra","giraffe","backpack","umbrella","handbag","tie","suitcase","frisbee",
"skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard",
"tennis racket","bottle","wine glass","cup","fork","knife","spoon","bowl","banana","apple",
"sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","sofa","pottedplant",
"bed","diningtable","toilet","tvmonitor","laptop","mouse","remote","keyboard","cell phone","microwave",
"oven","toaster","sink","refrigerator","book","clock","vase","scissors","teddy bear","hair drier","toothbrush"
]
{
"num": 1,
"obj": [
{
"prob": 0.938137174,
"x": 179,
"y": 186,
"w": 330,
"h": 273,
"type": "person"
}
],
"running": "Object Recognition"
}
Detects specified color regions and returns the coordinates of the color area.
You can directly adjust the LAB threshold slider to filter out the background and get the interested color area. You can also directly frame the interested color area in the picture, the system will automatically calculate the color occupying the most proportion of the target area and filter out the background. You can further adjust the slider based on the calculation to get better filtering effect. Clicking the "To Mask Mode" button will switch to Mask mode, where you can directly see the filtering effect. Clicking the "To RGB Mode" button will switch back to RGB mode.
Before
the following operations, please switch the function to Color Tracker
{
"function": "Color Tracker",
"args": ""
}
4.3.1 Specify LAB Threshold
// * LAB threshold mapped to 0~255
{
"config":"Color Tracker",
"l_min":0, // 0 ~ 255
"l_max":0, // 0 ~ 255
"a_min":0, // 0 ~ 255
"a_max":0, // 0 ~ 255
"b_min":0, // 0 ~ 255
"b_max":0 // 0 ~ 255
}
{
"running":"Color Tracker",
"msg":"Data updated."
}
4.3.2 Specify ROI (Automatic Threshold Calculation)
{
{
"config":"Color Tracker",
"x":0, // 0 ~ 640
"y":0, // 0 ~ 480
"w":30,
"h":30,
}
// * va and vb refer to the color dispersion degree within the ROI. If the dispersion is high, the tracking effect will be poor.
{
"running":"Color Tracker",
"a_cal":0.0,
"b_cal":0.0, // calculated threshold
"va":0.0,
"vb":0.0, // color dispersion rate
"l_min":0, // fixed value 0
"l_max":255, // fixed value 255
"a_min":0, // a_cal - (10 + (int)(va / 2.0f))
"a_max":0, // a_cal + (10 + (int)(va / 2.0f))
"b_min":0, // b_cal - (10 + (int)(vb / 2.0f))
"b_max":0 // b_cal + (10 + (int)(vb / 2.0f))
}
{
"running":"Color Tracker",
"cx": 0, // center X coordinate
"cy": 0, // center Y coordinate
"r": 0, // radius
"mx": 0, // moment x position
"my": 0 // moment y position
}
Detects road lines in the frame, fits them into straight lines, and returns the line angle and coordinates.
You can directly adjust the LAB threshold slider to filter out the background and get the interested color area. You can also directly frame the interested color area in the picture, the system will automatically calculate the color occupying the most proportion of the target area and filter out the background. You can further adjust the slider based on the calculation to get better filtering effect. Clicking the "To Mask Mode" button will switch to Mask mode, where you can directly see the filtering effect. Clicking the "To RGB Mode" button will switch back to RGB mode.
Before the following operations, please switch the function to Lane Line Tracker
{
"function": "Lane Line Tracker",
"args": ""
}
5.3.1 Specify LAB Threshold
5.3.1 Specify LAB Threshold
// * Map LAB thresholds to 0~255
{
"config": "Lane Line Tracker",
"l_min": 0, // 0 ~ 255
"l_max": 0, // 0 ~ 255
"a_min": 0, // 0 ~ 255
"a_max": 0, // 0 ~ 255
"b_min": 0, // 0 ~ 255
"b_max": 0, // 0 ~ 255
}
{
"running": "Lane Line Tracker",
"msg": "Data updated."
}
5.3.2 Specify ROI (Automatically Calculate Thresholds)
{
"config": "Lane Line Tracker",
"x": 0, // 0 ~ 640
"y": 0, // 0 ~ 480
"w": 30,
"h": 30,
}
//* va and vb refer to the color dispersion within the ROI. A higher dispersion indicates poorer segmentation results.
{
"running": "Lane Line Tracker",
"a_cal": 0.0,
"b_cal": 0.0, // Calculated thresholds
"va": 0.0,
"vb": 0.0, // Color dispersion rates
"l_min": 0, // Fixed value 0
"l_max": 255, // Fixed value 255
"a_min": 0, // a_cal - (10 + (int)(va / 2.0f))
"a_max": 0, // a_cal + (10 + (int)(va / 2.0f))
"b_min": 0, // b_cal - (10 + (int)(vb / 2.0f))
"b_max": 0 // b_cal + (10 + (int)(vb / 2.0f))
}
{
"running": "Lane Line Tracker",
"x": 0,
"y": 0, // Base point of the fitted line
"k": 0 // Slope of the fitted line
}
Track a selected target in the frame, using the MOSSE algorithm.
Simply box out the target of interest on the screen.
Before the following operations, please switch the function to Target Tracker
{
"function": "Target Tracker",
"args": ""
}
{
"running": "Target Tracker",
"x": 0,//0~640
"y": 0,//0~480
"w": 0,
"h": 0
}
Detect and track moving targets, returning the coordinates and angle of the target.
Click the 'Set as background' button to determine the background. The algorithm can adapt to slowly changing backgrounds.
Before the following operations, please switch the function to Motion Tracker
{
"function": "Motion Tracker",
"args": ""
}
7.3.1 Determine Background
Send
// Sending this command will determine the background
{
"config": "Motion Tracker",
"operation": "update"
}
Receive
{
"running": "Motion Tracker",
"msg": "Background updated."
}
{
"running": "Motion Tracker",
"num": 2,
"roi": [
{
"x": 0,
"y": 0,
"w": 0,
"h": 0,
"angle": 0.0,
"area": 0
},
{
"x": 0,
"y": 0,
"w": 0,
"h": 0,
"angle": 0.0,
"area": 0
}
]
}
This function can real-time train and classify objects within the green target box. The trained feature values can be saved on the device for future use.
Before the following operations, please switch the function to Online Classifier
{
"function": "Online Classifier",
"args": ""
}
8.3.1 Train
Send
//This command will put the device into training mode and extract features once to be stored under the specified class. If the class_id does not exist, it will create this class.
{
"config": "Online Classifier",
"operation": "train",
"class_id": 1, // Integer (0 ~ N), ID of the class
"class": "class_1" // String, name of the class
}
Receive
{
"running": "Online Classifier",
"msg": "Training [class name] [num of training] times"
}
8.3.2 Save&Run
Send
{
"config": "Online Classifier",
"operation": "saverun",
}
Receive
{
"running": "Online Classifier",
"msg": "Save and run."
}
8.3.3 Reset
Send
//This command will put the device into training mode and clear all categories.
{
"config": "Online Classifier",
"operation": "reset",
}
Receive
{
"running": "Online Classifier",
"msg": " Please take a picture."
}
{
"running": "Online Classifier",
"class_num": 2, // Number of recognized classes
"best_match": "class_1", // Best matching class
"best_score": 0.83838, // Best matching score
"class": [ // Score of each class
{
"name": "class_1",
"score": 0.83838
},
{
"name": "class_2",
"score": 0.66244
}
]
}
Detect and recognize faces.
Before proceeding with the following operations, please switch the function to Face Recognition
{
"function": "Face Recognition",
"args": ""
}
9.3.1 Train
Send
// To create a new face, please provide the face_id in sequence (0 ~ N).
{
"config":"Face Recognition",
"operation":"train",
"face_id":1, // Integer (0 ~ N), the ID of the face
"name":"tom" // String, the name of the face
}
// For example, if there are already 3 faces (0~2), to create a new face, the id should be specified as 3.
Receive (Success)
{
"running":" Face Recognition ",
"msg":"Training tom" // Training face name
}
Receive (Error)
{
"running":"Face Recognition",
"msg":"Invalid face id"
}
9.3.2 Stop Train
Send
{
"config":" Face Recognition ",
"operation":" stoptrain",
}
Receive
{
"running":"Face Recognition",
"msg":"Exit training mode."
}
9.3.3 Save&Run
Send
{
"config":" Face Recognition ",
"operation":"saverun",
}
Receive
{
"running":"Face Recognition",
"msg":"Faces saved."
}
9.3.4 Reset
Send
// This command will delete all faces.
{
"config":"Face Recognition",
"operation":"reset",
}
Receive
{
"running":"Face Recognition",
"msg":"Reset success"
}
9.4.1 Training Mode
{
"running":"Face Recognition",
"status":"training", // training or missing
"x":0,
"y":0,
"w":0,
"h":0, // face detection bounding box
"prob":0, // detection confidence
"name":0,
}
9.4.2 Normal Mode (Matching Score > 0.5)
{
"running":"Face Recognition",
"num":1, // number of faces recognized
"face":[
{
"x":0, // 0 ~ 320
"y":0, // 0 ~ 240
"w":30,
"h":30, // face detection bounding box
"prob":0, // detection confidence
"match_prob":0.8, // matching confidence
"name": "tom",
"mark":[ // landmarks
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
]
},
]
}
9.4.3 Normal Mode (Matching Score <= 0.5)
{
"running":"Face Recognition",
"num":1, // number of faces recognized
"face":[
{
"x":0, // 0 ~ 320
"y":0, // 0 ~ 240
"w":30,
"h":30, // face detection bounding box
"prob":0, // confidence
"name": "unidentified",
"mark":[ // landmarks
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
]
},
]
}
Detect faces in the frame and provide 5-point landmarks.
Before proceeding with the following operations, please switch the function to Face Detector
{
"function": "Face Detector",
"args": ""
}
{
"running":"Face Detector",
"num":1, // number of faces recognized
"face":[
{
"x":0,
"y":0,
"w":30,
"h":30, // face detection bounding box
"prob":0, // confidence
"mark":[ // landmarks
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
},
{
"x":0,
"y":0
}
]
}
]
}
Detect shapes in the frame and calculate their area. It can recognize squares, rectangles, triangles, pentagons, and circles.
Click the 'Set as background' button to set the background. This algorithm can adapt to slowly changing backgrounds.
Before proceeding with the following operations, please switch the function to Shape Detector
{
"function": "Shape Detector",
"args": ""
}
Send
// Sending this command will set the background
{
"config":"Shape Detector",
"operation":"update"
}
Receive
{
"running":"Shape Detector",
"msg":"Background updated."
}
{
"running":"Shape Detector",
"num":2,
"shape":[
{
"name":"Rectangle", // "unidentified", "triangle", "square", "rectangle", "pentagon", "circle"
"x":0,
"y":0,
"w":0,
"h":0,
"angle":0.0, // can be used when the shape is a square or rectangle
"area":0
},
{
"name":"Rectangle", // "unidentified", "triangle", "square", "rectangle", "pentagon", "circle"
"x":0,
"y":0,
"w":0,
"h":0,
"angle":0.0, // can be used when the shape is a square or rectangle
"area":0
}
]
}
Match any given shape (although it is better if the shape does not contain curves), the uploaded shape will be converted into feature data and saved on the device for future use.
To be developed, not supported yet.
// The shape returned here is the filename of the uploaded template, please note if the confidence rate is below 30% it will be labeled as unidentified.
{
"running":"Shape Matching",
"num":2,
"shape":[
{
"name":"arrow", // Your custom shape name, when confidence rate is less than 30 it cannot be identified
"max_score":83, // Confidence rating score, if the shape is unknown, it is not present
"x":0,
"y":0,
"w":0,
"h":0,
"area":0
},
{
"name":"unidentified", // Your custom shape name, when the confidence score is less than 30 it cannot be identified
"x":0,
"y":0,
"w":0,
"h":0,
"area":0
},
]
}
Capture audio through the microphone on the device, perform real-time FFT (Fast Fourier Transform), and plot a time-frequency graph. The green chart below is the audio's RMS, indicating the current loudness level.
None
None
During recognition, UnitV2 will continuously output sample data in JSON format through the serial port (bottom HY2.0-4P interface) (UART: 115200bps 8N1
). Below are example programs for reading recognition results on different platforms.
JSON strings can be parsed using the ArduinoJson library.
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
}
void loop() {
if(Serial2.available()) {
String recvStr = Serial2.readStringUntil('/n');
if(recvStr[0] == '{'){
Serial.print(recvStr);
}
}
}
import machine
import json
uart1 = machine.UART(1, tx=16, rx=17)
uart1.init(115200, bits=8, parity=None, stop=1)
PROTOCOL_START = b'{'[0]
while True:
if uart1.any():
data = uart1.readline()
if data[0] == PROTOCOL_START:
json_data = json.loads(data)
from json.decoder import JSONDecodeError
import subprocess
import json
import base64
import serial
import time
from datetime import datetime
from PIL import Image
import os
import io
uart_grove = serial.Serial('/dev/ttyS0', 115200, timeout=0.1)
reconizer = subprocess.Popen(['/home/m5stack/payload/bin/object_recognition', '/home/m5stack/payload/uploads/models/nanodet_80class'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
reconizer.stdin.write("_{\"stream\":1}\r\n".encode('utf-8'))
reconizer.stdin.flush()
img = b''
while True:
today = datetime.now()
path = str(today.strftime("%Y_%m_%d") + "/")
newpath = "/media/sdcard/" + path
line = reconizer.stdout.readline().decode('utf-8').strip()
if not line:
break # Process finished or empty line
try:
doc = json.loads(line)
if 'img' in doc:
byte_data = base64.b64decode(doc["img"])
img = bytes(byte_data)
elif 'num' in doc:
for obj in doc['obj']:
uart_grove.write(str(obj['type'] + '\n').encode('utf-8'))
if obj['type'] == "aeroplane":
print('aeroplane ' + today.strftime("%Y_%m_%d_%H_%M_%S"))
if os.path.exists(newpath):
image_path = newpath + today.strftime("%Y_%m_%d_%H_%M_%S") + ".jpg"
img = Image.open(io.BytesIO(byte_data))
img.save(image_path, 'jpeg')
else:
os.mkdir(newpath)
image_path = newpath + today.strftime("%Y_%m_%d_%H_%M_%S") + ".jpg"
img = Image.open(io.BytesIO(byte_data))
img.save(image_path, 'jpeg')
time.sleep(1)
else:
print('Not detect '+ today.strftime("%Y_%m_%d_%H_%M_%S"))
except JSONDecodeError as e:
print("Error: Invalid JSON string")
print("JSONDecodeError:", str(e))