-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#ifndef __OBJECTCLASSLIST_H__ | ||
#define __OBJECTCLASSLIST_H__ | ||
|
||
struct ObjectDetectionItem { | ||
uint8_t index; | ||
const char* objectName; | ||
uint8_t filter; | ||
}; | ||
|
||
// List of objects the pre-trained model is capable of recognizing | ||
// Index number is fixed and hard-coded from training | ||
// Set the filter value to 0 to ignore any recognized objects | ||
ObjectDetectionItem itemList[80] = { | ||
{0, "person", 1}, | ||
{1, "bicycle", 1}, | ||
{2, "car", 1}, | ||
{3, "motorbike", 1}, | ||
{4, "aeroplane", 1}, | ||
{5, "bus", 1}, | ||
{6, "train", 1}, | ||
{7, "truck", 1}, | ||
{8, "boat", 1}, | ||
{9, "traffic light", 1}, | ||
{10, "fire hydrant", 1}, | ||
{11, "stop sign", 1}, | ||
{12, "parking meter", 1}, | ||
{13, "bench", 1}, | ||
{14, "bird", 1}, | ||
{15, "cat", 1}, | ||
{16, "dog", 1}, | ||
{17, "horse", 1}, | ||
{18, "sheep", 1}, | ||
{19, "cow", 1}, | ||
{20, "elephant", 1}, | ||
{21, "bear", 1}, | ||
{22, "zebra", 1}, | ||
{23, "giraffe", 1}, | ||
{24, "backpack", 1}, | ||
{25, "umbrella", 1}, | ||
{26, "handbag", 1}, | ||
{27, "tie", 1}, | ||
{28, "suitcase", 1}, | ||
{29, "frisbee", 1}, | ||
{30, "skis", 1}, | ||
{31, "snowboard", 1}, | ||
{32, "sports ball", 1}, | ||
{33, "kite", 1}, | ||
{34, "baseball bat", 1}, | ||
{35, "baseball glove", 1}, | ||
{36, "skateboard", 1}, | ||
{37, "surfboard", 1}, | ||
{38, "tennis racket", 1}, | ||
{39, "bottle", 1}, | ||
{40, "wine glass", 1}, | ||
{41, "cup", 1}, | ||
{42, "fork", 1}, | ||
{43, "knife", 1}, | ||
{44, "spoon", 1}, | ||
{45, "bowl", 1}, | ||
{46, "banana", 1}, | ||
{47, "apple", 1}, | ||
{48, "sandwich", 1}, | ||
{49, "orange", 1}, | ||
{50, "broccoli", 1}, | ||
{51, "carrot", 1}, | ||
{52, "hot dog", 1}, | ||
{53, "pizza", 1}, | ||
{54, "donut", 1}, | ||
{55, "cake", 1}, | ||
{56, "chair", 1}, | ||
{57, "sofa", 1}, | ||
{58, "pottedplant", 1}, | ||
{59, "bed", 1}, | ||
{60, "diningtable", 1}, | ||
{61, "toilet", 1}, | ||
{62, "tvmonitor", 1}, | ||
{63, "laptop", 1}, | ||
{64, "mouse", 1}, | ||
{65, "remote", 1}, | ||
{66, "keyboard", 1}, | ||
{67, "cell phone", 1}, | ||
{68, "microwave", 1}, | ||
{69, "oven", 1}, | ||
{70, "toaster", 1}, | ||
{71, "sink", 1}, | ||
{72, "refrigerator", 1}, | ||
{73, "book", 1}, | ||
{74, "clock", 1}, | ||
{75, "vase", 1}, | ||
{76, "scissors", 1}, | ||
{77, "teddy bear", 1}, | ||
{78, "hair dryer", 1}, | ||
{79, "toothbrush", 1}}; | ||
|
||
#endif |
156 changes: 156 additions & 0 deletions
156
Arduino/AMB82-mini/RTSP_YOLOv7_Tiny/RTSP_YOLOv7_TIiny.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
Example guide: | ||
https://www.amebaiot.com/en/amebapro2-arduino-neuralnework-object-detection/ | ||
NN Model Selection | ||
Select Neural Network(NN) task and models using modelSelect(nntask, objdetmodel, facedetmodel, facerecogmodel). | ||
Replace with NA_MODEL if they are not necessary for your selected NN Task. | ||
NN task | ||
======= | ||
OBJECT_DETECTION/ FACE_DETECTION/ FACE_RECOGNITION | ||
Models | ||
======= | ||
YOLOv3 model DEFAULT_YOLOV3TINY / CUSTOMIZED_YOLOV3TINY | ||
YOLOv4 model DEFAULT_YOLOV4TINY / CUSTOMIZED_YOLOV4TINY | ||
YOLOv7 model DEFAULT_YOLOV7TINY / CUSTOMIZED_YOLOV7TINY | ||
SCRFD model DEFAULT_SCRFD / CUSTOMIZED_SCRFD | ||
MobileFaceNet model DEFAULT_MOBILEFACENET/ CUSTOMIZED_MOBILEFACENET | ||
No model NA_MODEL | ||
*/ | ||
|
||
#include "WiFi.h" | ||
#include "StreamIO.h" | ||
#include "VideoStream.h" | ||
#include "RTSP.h" | ||
#include "NNObjectDetection.h" | ||
#include "VideoStreamOverlay.h" | ||
#include "ObjectClassList.h" | ||
|
||
#define CHANNEL 0 | ||
#define CHANNELNN 3 | ||
|
||
// Lower resolution for NN processing | ||
#define NNWIDTH 576 | ||
#define NNHEIGHT 320 | ||
|
||
VideoSetting config(VIDEO_FHD, 30, VIDEO_H264, 0); | ||
VideoSetting configNN(NNWIDTH, NNHEIGHT, 10, VIDEO_RGB, 0); | ||
NNObjectDetection ObjDet; | ||
RTSP rtsp; | ||
StreamIO videoStreamer(1, 1); | ||
StreamIO videoStreamerNN(1, 1); | ||
|
||
char ssid[] = "your_wifi_ssid"; // your network SSID (name) | ||
char pass[] = "your_wifi_password"; // your network password | ||
int status = WL_IDLE_STATUS; | ||
|
||
IPAddress ip; | ||
int rtsp_portnum; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
// attempt to connect to Wifi network: | ||
while (status != WL_CONNECTED) { | ||
Serial.print("Attempting to connect to WPA SSID: "); | ||
Serial.println(ssid); | ||
status = WiFi.begin(ssid, pass); | ||
|
||
// wait 2 seconds for connection: | ||
delay(2000); | ||
} | ||
ip = WiFi.localIP(); | ||
|
||
// Configure camera video channels with video format information | ||
// Adjust the bitrate based on your WiFi network quality | ||
config.setBitrate(2 * 1024 * 1024); // Recommend to use 2Mbps for RTSP streaming to prevent network congestion | ||
Camera.configVideoChannel(CHANNEL, config); | ||
Camera.configVideoChannel(CHANNELNN, configNN); | ||
Camera.videoInit(); | ||
|
||
// Configure RTSP with corresponding video format information | ||
rtsp.configVideo(config); | ||
rtsp.begin(); | ||
rtsp_portnum = rtsp.getPort(); | ||
|
||
// Configure object detection with corresponding video format information | ||
// Select Neural Network(NN) task and models | ||
ObjDet.configVideo(configNN); | ||
ObjDet.modelSelect(OBJECT_DETECTION, DEFAULT_YOLOV7TINY, NA_MODEL, NA_MODEL); | ||
ObjDet.begin(); | ||
|
||
// Configure StreamIO object to stream data from video channel to RTSP | ||
videoStreamer.registerInput(Camera.getStream(CHANNEL)); | ||
videoStreamer.registerOutput(rtsp); | ||
if (videoStreamer.begin() != 0) { | ||
Serial.println("StreamIO link start failed"); | ||
} | ||
|
||
// Start data stream from video channel | ||
Camera.channelBegin(CHANNEL); | ||
|
||
// Configure StreamIO object to stream data from RGB video channel to object detection | ||
videoStreamerNN.registerInput(Camera.getStream(CHANNELNN)); | ||
videoStreamerNN.setStackSize(); | ||
videoStreamerNN.setTaskPriority(); | ||
videoStreamerNN.registerOutput(ObjDet); | ||
if (videoStreamerNN.begin() != 0) { | ||
Serial.println("StreamIO link start failed"); | ||
} | ||
|
||
// Start video channel for NN | ||
Camera.channelBegin(CHANNELNN); | ||
|
||
// Start OSD drawing on RTSP video channel | ||
OSD.configVideo(CHANNEL, config); | ||
OSD.begin(); | ||
} | ||
|
||
void loop() { | ||
std::vector<ObjectDetectionResult> results = ObjDet.getResult(); | ||
|
||
uint16_t im_h = config.height(); | ||
uint16_t im_w = config.width(); | ||
|
||
Serial.print("Network URL for RTSP Streaming: "); | ||
Serial.print("rtsp://"); | ||
Serial.print(ip); | ||
Serial.print(":"); | ||
Serial.println(rtsp_portnum); | ||
Serial.println(" "); | ||
|
||
printf("Total number of objects detected = %d\r\n", ObjDet.getResultCount()); | ||
OSD.createBitmap(CHANNEL); | ||
|
||
if (ObjDet.getResultCount() > 0) { | ||
for (uint32_t i = 0; i < ObjDet.getResultCount(); i++) { | ||
int obj_type = results[i].type(); | ||
if (itemList[obj_type].filter) { // check if item should be ignored | ||
|
||
ObjectDetectionResult item = results[i]; | ||
// Result coordinates are floats ranging from 0.00 to 1.00 | ||
// Multiply with RTSP resolution to get coordinates in pixels | ||
int xmin = (int)(item.xMin() * im_w); | ||
int xmax = (int)(item.xMax() * im_w); | ||
int ymin = (int)(item.yMin() * im_h); | ||
int ymax = (int)(item.yMax() * im_h); | ||
|
||
// Draw boundary box | ||
printf("Item %d %s:\t%d %d %d %d\n\r", i, itemList[obj_type].objectName, xmin, xmax, ymin, ymax); | ||
OSD.drawRect(CHANNEL, xmin, ymin, xmax, ymax, 3, OSD_COLOR_WHITE); | ||
|
||
// Print identification text | ||
char text_str[20]; | ||
snprintf(text_str, sizeof(text_str), "%s %d", itemList[obj_type].objectName, item.score()); | ||
OSD.drawText(CHANNEL, xmin, ymin - OSD.getTextHeight(CHANNEL), text_str, OSD_COLOR_CYAN); | ||
} | ||
} | ||
} | ||
OSD.update(CHANNEL); | ||
|
||
// delay to wait for new results | ||
delay(100); | ||
} |