I have the object detection working and it working as a UVC Camera device working after enabling only X264 in UVCD_pram.h. but when i try and run both together it always crashes.
#include "WiFi.h"
#include "StreamIO.h"
#include "VideoStream.h"
#include "RTSP.h"
#include "NNObjectDetection.h"
#include "VideoStreamOverlay.h"
#include "ObjectClassList.h"
#include "UVCD.h"
#define CHANNEL 0
#define CHANNELNN 3
//#define STREAM_CHANNEL 0
// 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;
UVCD usb_uvcd;
NNObjectDetection ObjDet;
//RTSP rtsp;
//StreamIO videoStreamer(1, 1);
StreamIO videoStreamerNN(1, 1);
StreamIO videoStreamer(1, 1); // 1 Input Video -> 1 Output USB_CAM
char ssid[] = "Network_SSID"; // your network SSID (name)
char pass[] = "Password"; // your network password
int status = WL_IDLE_STATUS;
IPAddress ip;
int rtsp_portnum;
void setup()
{
Serial.begin(115200);
// 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();
usb_uvcd.configVideo(stream_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_uvcd.getStream(CHANNEL));
videoStreamer.registerOutput(usb_uvcd);
if (videoStreamer.begin() != 0) {
Serial.println("USB link start failed");
}
// 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("RTSP link start failed");
// }
// Start data stream from video channel
camera_uvcd.channelBegin(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 (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(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);
}
input param 0
data_format 2
memory_type 0
num_of_dims 4
quant_format 2
quant_data , scale=0.003922, zero_point=0
sizes 416 416 3 1 0 0
output param 0
data_format 2
memory_type 0
num_of_dims 4
quant_format 2
quant_data , scale=0.137945, zero_point=178
sizes 13 13 255 1 0 0
output param 1
data_format 2
memory_type 0
num_of_dims 4
quant_format 2
quant_data , scale=0.131652, zero_point=193
sizes 26 26 255 1 0 0
---------------------------------
HASHMAP ->70223a44(record-list) INIT SUCCESS
[ERROR] Input not initialized correctly!
[LINKER Err]mm siso: input or output not setUSB link start failed
hal_voe_ready 0x0 0xbf1208
read fcs_status 0x000000bf
[video_init] uvcd iq is null, use default.
[video_init] uvcd SNR is null, use default.
IQ:FW size (3)
sensor:date 21586/76/56 version:735B�����������������������
sensor:FW size (-1)
Bus Fault:
SCB Configurable Fault Status Reg = 0x00000400
Bus Fault Status:
BusFault Address Reg is invalid(Asyn. BusFault)
Imprecise data bus error:
a data bus error has occurred, but the return address in the stack frame is not related to the instruction that caused the error.
S-domain exception from Handler mode, Standard Stack frame on S-MSP
Registers Saved to stack