Hi, I have tried to merge image classification and UVCD ObjectDetection Loop follow your instruction.
here is my code
/*
This example describes how to use USB UVCD api with OBJECT_DETECTION.
In this example, the device is setup to function as a USB camera.
Connect to PC and use the device as a USB camera.
Perform objects prediction when the device is connect to PC and PotPlayer.
Example guide: TBD
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 "StreamIO.h"
#include "VideoStream.h"
#include "UVCD.h"
#include "NNImageClassification.h"
#include "VideoStreamOverlay.h"
#include "ClassificationClassList.h"
#define IMAGERGB 1
#define STREAM_CHANNEL 0
#define CHANNELNN 3
int reconnect = 0;
int disconnect = 0;
Video camera_uvcd;
//NNObjectDetection ObjDet;
NNImageClassification imgclass;
UVCD usb_uvcd;
// Lower resolution for NN processing
#define NNWIDTH 224
#define NNHEIGHT 224
StreamIO videoStreamer(1, 1); // 1 Input Video -> 1 Output USB_CAM
StreamIO videoStreamerNN(1, 1);
VideoSetting stream_config(USB_UVCD_STREAM_PRESET);
VideoSetting configNN(NNWIDTH, NNHEIGHT, 10, VIDEO_RGB, 0);
VideoSetting config(VIDEO_FHD, 30, VIDEO_H264, 0);
void setup()
{
Serial.begin(115200);
// Configure camera video channel with video format information
camera_uvcd.configVideoChannel(STREAM_CHANNEL, stream_config);
camera_uvcd.configVideoChannel(CHANNELNN, configNN);
// Configure usb_uvcd with identical video format information
usb_uvcd.configVideo(stream_config);
camera_uvcd.videoInit();
// 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();
imgclass.configVideo(configNN);
imgclass.configInputImageColor(IMAGERGB);
imgclass.setResultCallback(ICPostProcess);
imgclass.modelSelect(IMAGE_CLASSIFICATION, NA_MODEL, NA_MODEL, NA_MODEL, NA_MODEL, DEFAULT_IMGCLASS);
imgclass.begin();
// Configure StreamIO object to stream data from camera video channel to usb_uvcd
videoStreamer.registerInput(camera_uvcd.getStream(STREAM_CHANNEL));
videoStreamer.registerOutput(usb_uvcd);
if (videoStreamer.begin() != 0) {
Serial.println("StreamIO link start failed");
}
// Start data stream from video channel
camera_uvcd.channelBegin(STREAM_CHANNEL);
// Configure StreamIO object to stream data from RGB video channel to object detection
videoStreamerNN.registerInput(camera_uvcd.getStream(CHANNELNN));
videoStreamerNN.setStackSize();
videoStreamerNN.setTaskPriority();
videoStreamerNN.registerOutput(imgclass);
if (videoStreamerNN.begin() != 0) {
Serial.println("StreamIO link start failed");
}
// Start video channel for NN
camera_uvcd.channelBegin(CHANNELNN);
// Start usb uvcd for NN
usb_uvcd.nnbegin(camera_uvcd.getStream(STREAM_CHANNEL), videoStreamer.linker, STREAM_CHANNEL, CHANNELNN, camera_uvcd.videostream_status(STREAM_CHANNEL));
//OSD.configVideo(STREAM_CHANNEL, config);
//OSD.begin();
}
void loop()
{
}
void disconnectNN()
{
camera_uvcd.channelEnd(CHANNELNN); // Stop video channel from NN
camera_uvcd.channelBegin(STREAM_CHANNEL); // Stop video channel from video channel
reconnect = 1;
disconnect = 1;
}
void reconnectNN()
{
camera_uvcd.channelBegin(CHANNELNN); // Start video channel for NN
camera_uvcd.channelBegin(STREAM_CHANNEL); // Start video channel for video channel
reconnect = 0;
disconnect = 0;
}
void ICPostProcess(void)
{
if (!usb_uvcd.isUsbUvcConnected(camera_uvcd.videostream_status(STREAM_CHANNEL))) {
Serial.println("USB UVC device disconnected");
// Handle disconnection processes
if (disconnect == 0) {
disconnectNN();
}
return;
}
else {
// Handle reconnection or restart processes
if (reconnect == 1) {
reconnectNN();
}
int class_id = imgclass.classID();
if (imgclassItemList[class_id].filter) { // header file
float prob = imgclass.score();
printf("class %d, score: %f, name: %s\r\n", class_id, prob, imgclassItemList[class_id].imgclassName);
}
}
delay(500);
}
and now the problem is the webcam works fine, but I did not get any output from image classification
below is the log from plug in and open/close PotPlayer
== Rtl8735b IoT Platform ==
[Normal mode]
BootFromNORFlash
[Start Boot ROM...]
=== Load PARTBL ===
=== Load Done ===
=== Load ISP_IQ ===
[fcs chk pass]
ISP_IQ @ 0x8461080, 0x2ff80, 0x0
mfcs_data version 0x00010001
fcs_data version 0x00010101
=== Process ISP_IQ ===
=== Load Done ===
=== Load BL ===
[Image Start Table @ 0x18200]
=== Load Done ===
== Boot Loader ==
Oct 24 2024:17:41:10
=== Load FCS Para ===
=== Load Done ===
[crc pass]
=== Load ISP_IQ Sensor ===
ISP_IQ @ 0x8461080, 0x2ff80
=== Process ISP_IQ ===
=== Load Done ===
=== Load FW1 ===
FW_ISP_IQ @ 0x8061080, 0x31f80
=== Process FW_ISP_IQ ===
DRAM_TYPE is DDR2 128MB.
ddr_freq = 533
VOE flash @ 0x8093080, 0x80f80
FCS KM_status 0x00002081 err 0x0000200a
Wait KM fcs done 0 us
FCS TM_status 0x003f0000
store fcs data for application
It don't do the sensor initial process
RAM TM_STATUS 0x00bf1208 err 0x00001208
read fcs_status 0x000000bf
read fcs_status 0x000000bf
=== Process VOE IMG ===
[Image Start Table @ 0x20106200]
RAM Load @ 0x8114100->0x20106200, 0x6260
DDR Load @ 0x811b080->0x70100000, 0x6dcb0
=== FW Load Done ===
Boot Loader <==
== RAM Start ==
Build @ 17:32:16, Oct 24 2024
$8735b>OTG DRIVER VER: 0826
p_data.len= 2
uvc_hs_streaming_ep= 83
[OTG Err]ERROR:: ep_enable, bogus device state
[video_voe_presetting] fps:30 w:1920 h:1080
fwin(1),enc_en(0),IQ_OFFSET = 0x17b60
fwin(1),enc_en(0),SENSOR_OFFSET = 0x2fba0
sensor id 1 iq_data 17b60 sensor_data 2fba0
fwin(1),enc_en(0),IQ_OFFSET = 0x17b60
fwin(1),enc_en(0),SENSOR_OFFSET = 0x2fba0
sensor id 1 iq_data 17b60 sensorset_alt interface 0 alt =0
set_alt interface 1 alt =0
_daset_alt interface 1 alt =0
ta 2fba0
NN IRQ default priority : 0, set to 9
VIPLite Drv version 1.12.0
Deploy Image Classification
set_alt interface 1 alt =0
input 0 dim 416 416 3 1, data format=2, quant_format=2, scale=0.003922, zero_point=0
ouput 0 dim 52 52 255 1, data format=2, scale=0.003919, zero_point=0
ouput 1 dim 26 26 255 1, data format=2, scale=0.003921, zero_point=0
ouput 2 dim 13 13 255 1, data format=2, scale=0.003922, zero_point=0
---------------------------------
input count 1, output count 3
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.003919, zero_point=0
sizes 52 52 255 1 0 0
output param 1
data_format 2
memory_type 0
num_of_dims 4
quant_format 2
quant_data , scale=0.003921, zero_point=0
sizes 26 26 255 1 0 0
output param 2
data_format 2
memory_type 0
num_of_dims 4
quant_format 2
quant_data , scale=0.003922, zero_point=0
sizes 13 13 255 1 0 0
---------------------------------
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 (98342)
sensor:date 2024/9/12 version:RTL8735B_VOE_1.5.7.0
sensor:FW size (5412)
sensor timestamp: 2024/09/12
iq timestamp: 2023/05/15 14:48:54
voe_heap malloc 0x7020b080, size 19917824
ISP:1 ENC:1 H265:1 NN:1
hal_voe_ready 0x0 0xbf1208
voe :RTL8735B_VOE_1.5.8.0
sensor:RTL8735B_VOE_1.5.7.0
hal :RTL8735B_VOE_1.5.8.0
load time sensor:68us iq:1222us itcm:0us dtcm:0us ddr:0us ddr2:0us
Set H264 default HIGH profile
[video_pre_init_procedure] START
[VOE]ext_in = 0 sync = 0
[VOE][Ini set0]init dn 0 hdr 0 mirrorflip 0xf0
[VOE]g_init_fps: 30
[VOE]md init success
[VOE]algo ver 187ea48
[VOE]pack_v 0x0000 0x0002 cus_v 0 iq_id 0 dn 0 day 0 night 1 other 2 offset 224 length 16436 iq_size 32716
[VOE]Ver 0x0001000c Fast3A Cnt AE 1 AWB 1 period AE 5 AWB 1 delay 0 0
[VOE]hdr_mode 0 sensor driver num 1
[VOE]fps max 30.000000 min 2.000000
[VOE]exposure_step 29.629629
[VOE]change sensor mode => 1920x1080@30.000000fps - 'linear'
[VOE]min_fps 2.000000, max_fps 30.000000, exp_step 29.629629 dyn_fps 30.000000
[VOE]md ver 0x6d640100
[VOE]ae ver 0x61650200
[VOE]awb ver 0x77620100
[VOE]short exp mode is not implemented by this sensor.
[VOE]cur_hdr_mode = 0
[VOE]VOE MEM Size = 19451 Used= 3565 KB Free=15885 KB (16266688)
[VOE]stream 0 buffer 0: 0x70586700 size 3110400
[VOE]stream 0 buffer 1: 0x7087de00 size 3110400
[VOE]first_config_osd2_block_num[0]: 1
[VOE]osd2_block_num[0]: 24
[VOE]NV12 1920x1080 1/30
[VOE]dynamic set fps 0 -> 30 ok
[VOE]short exp mode is not implemented by this sensor.
[VOE]sensor power on
[VOE]early mirror/flip 0 0
[VOE]zoom crop default setting
[VOE]cropw: 1920, croph: 1080
[VOE]scale down set_mcrop
[VOE]status == 1718
[VOE]buffer size == (0x70bb51a0) (1307776 259200) queue(239)
[VOE]Set rate control: bpsqp -1 qpRange I[ 0, 51] PB[ 0, 51] 1048576 bps pic 1 skip 0 hrd 0 cpbSize 1000000 bitrateWindow 80 intraQpDelta -5 fixedIntraQp 0
[VOE]Set PreP: input [VOE]frame_e1920x1080 :nd: sensor d offset idn't initia0x0 : formalize done !
ion 0cc 0 : scaling 0 : scaling format 0
[VOE]vcenc_set_ref_pic_set() NULL
hal_voe_send2voe too long 182310 cmd 0x00000206 p1 0x00000000 p2 0x00000000
inputRateNumer[10] < outputRateNumer[30], Set inputRateNumer --> outputRateNumer
[VOE]ext_in = 0 sync = 0
[VOE]isp_device_probe had done
[VOE]isp_soc_start already done
[VOE]VOE MEM Size = 19451 Used= 17688 KB Free= 1762 KB (1804768)
[VOE]stream 4 buffer 0: 0x71351300 size 150528
[VOE]stream 4 buffer 1: 0x71376000 size 150528
[VOE]RGB3 224x224 1/10
[VOE]scale down set_mcrop
[VOE]status == 1718
[VOE]release s4 isp buffer 0
[VOE][WARN]useless release s4 slot0 status 0x00000000
[VOE]release s4 isp b[VOE][WARN]slot full : s0 int 0x00000004 buf 0x00000088 time 1293486 cnt 0 slot0 dn 1 rls 0 slot1 1 0 osd_t dn 1 0 rel 0 0
uffer 1
[VOE][WARN]useless release s4 slot1 status 0x00000000
Image Classification tick[76]
USB UVC device disconnected
[VOE]rts_rtsv_streamoff done <1118>
[VOE]rts_rtsv_request_bufs off done<1125>
[VOE]isp_close_stream success <1864>
[VOE]rt_osd2_deinit success <1882>
[VOE]isp_free_buffer success <2001>
hal_voe_send2voe too long 64996 cmd 0x00000207 p1 0x00000000 p2 0x00000004
Set H264 default HIGH profile
[VOE]ext_in = 0 sync = 0
[VOE]isp_device_probe had done
[VOE]isp_soc_start already done
[VOE]VOE MEM Size = 19451 Used= 17693 KB Free= 1757 KB (1799520)
[VOE] isp_locate_buffer malloc buffer failed
[VOE]isp_locate_buffer ch0 failed -1
VOE command 0x206 fail ret 0x1
VOE_OPEN_CMD command fail
hal_video_open fail
fun_suspend
fun_suspend
streaming request (req 81 cs 01)
probe
streaming request (req 01 cs 01)
setting commit control, length = 26
format ->7016ada4
interval[0] = 416666
format = 3 w = 1920 h = 1080 fps = 416666
streaming request (req 81 cs 01)
probe
streaming request (req 83 cs 01)
format ->7016ad8c ->7016ad8c
Type_ = 0finish output task
hal_video_output_task closed
format ->7016ad8c ->7016ad8c size 4147200
streaming request (req 82 cs 01)
format ->7016ad8c ->7016ad8c
Type_ = 0
format ->7016ad8c ->7016ad8c size 4147200
[VOE]sensor power off
[VOE]rts_rtsv_streamoff done <1118>
[VOE]rts_rtsv_request_bufs off done<1125>
[VOE]isp_close_stream success <1864>
[VOE]ch: 0 rt_osd2_deinit
[VOE]rt_osd2_deinit success <1882>
[VOE]Total HW Memory: 6528032
[VOE]Total SWHW Memory: 51456
[VOE]Total SW Memory: 16320
[VOE]Total Memory: 6595808
[VOE] isp_free_buffer no buffer need to be free
[VOE]isp_free_buffer failed -1
[VOE]voe close failed 0x10
hal_voe_send2voe too long 145992 cmd 0x00000207 p1 0x00000000 p2 0x00000000
VOE command 0x207 fail ret 0x1
VOE_CLOSE_CMD command fail ffffffff
hal_video_close fail
hal_voe_ready 0x0 0x1718
streaming request (req 01 cs 01)
setting commit control, length = 26
format ->7016ada4
interval[0] = 416666
format = 3 w = 1920 h = 1080 fps = 416666
streaming request (req 81 cs 01)
probe
streaming request (req 01 cs 02)
setting set_alt interface 1 alt =1
commit control, length = 26
setting commit control, length = 26
format ->7016ada4
interval[0] = 416666
format = 3 w = 1920 h = 1080 fps = 416666
hal_voe_ready 0x0 0x800000
read fcs_status 0x00000080
[video_init] uvcd iq is null, use default.
[video_init] uvcd SNR is null, use default.
IQ:FW size (98342)
sensor:date 2024/9/12 version:RTL8735B_VOE_1.5.7.0
sensor:FW size (5412)
sensor timestamp: 2024/09/12
iq timestamp: 2023/05/15 14:48:54
RAM TM_STATUS 0x00801209 err 0x00001209
hal_voe_fcs_check_km_run_bypass 4617
voe:date 2024/10/18 version:RTL8735B_VOE_1.5.8.0
voe:FW size itcm(21792) dtcm(992) ddr(259992) ddr2(241794)
read fcs_status 0x00000080
ISP:1 ENC:1 H265:1 NN:1
hal_voe_ready 0x1209 0x801209
voe :RTL8735B_VOE_1.5.8.0
sensor:RTL8735B_VOE_1.5.7.0
hal :RTL8735B_VOE_1.5.8.0
load time sensor:69us iq:1229us itcm:283us dtcm:15us ddr:3240us ddr2:4155us
Set H264 default HIGH profile
[video_pre_init_procedure] START
[VOE]ext_in = 0 sync = 0
[VOE][Ini set0]init dn 0 hdr 0 mirrorflip 0xf0
[VOE]g_init_fps: 30
[VOE]md init success
[VOE]algo ver 187ea48
[VOE]pack_v 0x0000 0x0002 cus_v 0 iq_id 0 dn 0 day 0 night 1 other 2 offset 224 length 16436 iq_size 32716
[VOE]Ver 0x0001000c Fast3A Cnt AE 1 AWB 1 period AE 5 AWB 1 delay 0 0
[VOE]hdr_mode 0 sensor driver num 1
[VOE]fps max 30.000000 min 2.000000
[VOE]exposure_step 29.629629
[VOE]change sensor mode => 1920x1080@30.000000fps - 'linear'
[VOE]min_fps 2.000000, max_fps 30.000000, exp_step 29.629629 dyn_fps 30.000000
[VOE]md ver 0x6d640100
[VOE]ae ver 0x61650200
[VOE]awb ver 0x77620100
[VOE]short exp mode is not implemented by this sensor.
[VOE]cur_hdr_mode = 0
[VOE]VOE MEM Size = 19451 Used= 3565 KB Free=15885 KB (16266688)
[VOE]stream 0 buffer 0: 0x70586700 size 3110400
[VOE]stream 0 buffer 1: 0x7087de00 size 3110400
[VOE]first_config_osd2_block_num[0]: 1
[VOE]osd2_block_num[0]: 24
[VOE][Ini set] ae gain 256 exp 10000
[VOE][Ini set] awb r_gain 361 b_gain 378
[VOE][Ini set] gray mode off
[VOE][Ini set] mirrorflip 0xf0
[VOE][Ini set] BRIGHTNESS 0
[VOE][Ini set] SATURATION 40
[VOE][Ini set] CONTRAST 50
[VOE][Ini set] FLICKER 1
[VOE][Ini set] WDR_MODE 2
[VOE][Ini set] WDR_LEVEL 80
[VOE]turn direct_i2c_mode 1
[VOE]NV12 1920x1080 1/30
[VOE]dynamic set fps 0 -> 30 ok
[VOE]short exp mode is not implemented by this sensor.
[VOE]sensor_start set fast ae cnt 2
[VOE]sensor power on
[VOE]early mirror/flip 0 0
[VOE]zoom crop default setting
[VOE]cropw: 1920, croph: 1080
[VOE]scale down set_mcrop
[VOE]status == 1718
[VOE]buffer size == (0x70bb4fa0) (1307776 259200) queue(279)
[VOE]Set rate control: bpsqp -1 qpRange I[ 0, 51] PB[ 0, 51] 1048576 bps pic 1 skip 0 hrd 0 cpbSize 1000000 bitrateWindow 72 intraQpDelta -5 fixedIntraQp 0
[VOE]Set PreP: input [VOE]frame_e1920x1080 :nd: sensor d offset idn't initia0x0 : formalize done !
ion 0cc 0 : scaling 0 : scaling format 0
[VOE]vcenc_set_ref_pic_set() NULL
hal_voe_send2voe too long 214667 cmd 0x00000206 p1 0x00000000 p2 0x00000000
stream on
set_alt interface 1 alt =0
deinit iso
Free the buffer
stream RESET
fun_suspend