I want to use Amb82-mini as USB camera with NN, the code below combines sample code of UVC_device and Object detection
The web cam works fine, but the NN seems not working,
the logs show below
#include "StreamIO.h"
#include "VideoStream.h"
#include "RTSP.h"
#include "NNObjectDetection.h"
#include "VideoStreamOverlay.h"
#include "ObjectClassList.h"
#include "UVCD.h"
#define STREAM_CHANNEL 0
#define CHANNELNN 3
// Lower resolution for NN processing
#define NNWIDTH 576
#define NNHEIGHT 320
VideoSetting config(USB_UVCD_STREAM_PRESET);
VideoSetting configNN(NNWIDTH, NNHEIGHT, 10, VIDEO_RGB, 0);
VideoSetting stream_config(USB_UVCD_STREAM_PRESET);
Video camera_uvcd;
NNObjectDetection ObjDet;
StreamIO videoStreamer(1, 1);
StreamIO videoStreamerNN(1, 1);
UVCD usb_uvcd;
unsigned long last_infer_time = 0;
const unsigned long infer_interval = 10000; // 每 1000ms 推論一次
void setup()
{
Serial.begin(115200);
// Configure camera video channel with video format information
config.setBitrate(2 * 1024 * 1024);
Camera.configVideoChannel(STREAM_CHANNEL, config);
Camera.configVideoChannel(CHANNELNN, configNN);
Camera.videoInit();
// Configure usb_uvcd with identical video format information
usb_uvcd.configVideo(config);
// Configure object detection with corresponding video format information
// Select Neural Network(NN) task and models
ObjDet.configVideo(configNN);
ObjDet.modelSelect(OBJECT_DETECTION, DEFAULT_YOLOV4TINY, NA_MODEL, NA_MODEL);
ObjDet.begin();
// Configure StreamIO object to stream data from camera video channel to usb_uvcd
videoStreamer.registerInput(Camera.getStream(STREAM_CHANNEL));
videoStreamer.registerOutput(usb_uvcd);
if (videoStreamer.begin() != 0) {
Serial.println("StreamIO link start failed");
}
// Start data stream from video channel
Camera.channelBegin(STREAM_CHANNEL);
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(STREAM_CHANNEL, config);
OSD.begin();
// Start usb uvcd
usb_uvcd.begin(Camera.getStream(STREAM_CHANNEL), videoStreamer.linker, STREAM_CHANNEL);
//usb_uvcd.begin(Camera.getStream(CHANNELNN), videoStreamerNN.linker, CHANNELNN);
}
void loop()
{
std::vector<ObjectDetectionResult> results = ObjDet.getResult();
uint16_t im_h = config.height();
uint16_t im_w = config.width();
Serial.print("Detected objects");
Serial.print(results.size(), DEC);
Serial.print("\n\n");
Serial.print("Total number of objects detected");
Serial.print(ObjDet.getResultCount(), DEC);
Serial.print("\n\n");
OSD.createBitmap(STREAM_CHANNEL);
if (ObjDet.getResultCount() > 0) {
for (int 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(STREAM_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(STREAM_CHANNEL, xmin, ymin - OSD.getTextHeight(STREAM_CHANNEL), text_str, OSD_COLOR_CYAN);
}
}
}
OSD.update(STREAM_CHANNEL);
delay(500);
}
YOLOv4t tick[60]
YOLOv4t tick[64]
YOLOv4t tick[58]
YOLOv4t tick[60]
YOLOv4t tick[64]
YOLOv4t tick[58]
YOLOv4t tick[60]
YOLOv4t tick[64]
YOLOv4t tick[58]
>>> YOLOv4t FPS = 6.00
YOLOv4t tick[60]
YOLOv4t tick[64]
YOLOv4t tick[58]
YOLOv4t tick[59]
YOLOv4t tick[62]
YOLOv4t tick[57]
YOLOv4t tick[59]
YOLOv4t tick[61]