@ -57,18 +57,21 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_
if ( Hardware : : TICI ( ) ) {
if ( Hardware : : TICI ( ) ) {
const int full_width_tici = 1928 ;
const int full_width_tici = 1928 ;
const int full_height_tici = 1208 ;
const int full_height_tici = 1208 ;
const int adapt_width_tici = 668 ;
const int adapt_width_tici = 954 ;
const int x_offset_tici = - 72 ;
const int y_offset_tici = - 144 ;
const int cropped_height = adapt_width_tici / 1.33 ;
const int cropped_height = adapt_width_tici / 1.33 ;
crop_rect = { full_width_tici / 2 - adapt_width_tici / 2 ,
crop_rect = { full_width_tici / 2 - adapt_width_tici / 2 + x_offset_tici ,
full_height_tici / 2 - cropped_height / 2 - 196 ,
full_height_tici / 2 - cropped_height / 2 + y_offset_tici ,
cropped_height / 2 ,
cropped_height / 2 ,
cropped_height } ;
cropped_height } ;
if ( ! s - > is_rhd ) {
if ( ! s - > is_rhd ) {
crop_rect . x + = adapt_width_tici - crop_rect . w + 32 ;
crop_rect . x + = adapt_width_tici - crop_rect . w ;
}
}
} else {
} else {
crop_rect = { 0 , 0 , height / 2 , height } ;
const int adapt_width = 372 ;
crop_rect = { 0 , 0 , adapt_width , height } ;
if ( ! s - > is_rhd ) {
if ( ! s - > is_rhd ) {
crop_rect . x + = width - crop_rect . w ;
crop_rect . x + = width - crop_rect . w ;
}
}
@ -95,7 +98,8 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_
auto [ resized_buf , resized_u , resized_v ] = get_yuv_buf ( s - > resized_buf , resized_width , resized_height ) ;
auto [ resized_buf , resized_u , resized_v ] = get_yuv_buf ( s - > resized_buf , resized_width , resized_height ) ;
uint8_t * resized_y = resized_buf ;
uint8_t * resized_y = resized_buf ;
libyuv : : FilterMode mode = libyuv : : FilterModeEnum : : kFilterBilinear ;
libyuv : : FilterMode mode = libyuv : : FilterModeEnum : : kFilterBilinear ;
libyuv : : I420Scale ( cropped_y , crop_rect . w ,
if ( Hardware : : TICI ( ) ) {
libyuv : : I420Scale ( cropped_y , crop_rect . w ,
cropped_u , crop_rect . w / 2 ,
cropped_u , crop_rect . w / 2 ,
cropped_v , crop_rect . w / 2 ,
cropped_v , crop_rect . w / 2 ,
crop_rect . w , crop_rect . h ,
crop_rect . w , crop_rect . h ,
@ -104,6 +108,21 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_
resized_v , resized_width / 2 ,
resized_v , resized_width / 2 ,
resized_width , resized_height ,
resized_width , resized_height ,
mode ) ;
mode ) ;
} else {
const int source_height = 0.7 * resized_height ;
const int extra_height = ( resized_height - source_height ) / 2 ;
const int extra_width = ( resized_width - source_height / 2 ) / 2 ;
const int source_width = source_height / 2 + extra_width ;
libyuv : : I420Scale ( cropped_y , crop_rect . w ,
cropped_u , crop_rect . w / 2 ,
cropped_v , crop_rect . w / 2 ,
crop_rect . w , crop_rect . h ,
resized_y + extra_height * resized_width , resized_width ,
resized_u + extra_height / 2 * resized_width / 2 , resized_width / 2 ,
resized_v + extra_height / 2 * resized_width / 2 , resized_width / 2 ,
source_width , source_height ,
mode ) ;
}
int yuv_buf_len = ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) * 6 ; // Y|u|v -> y|y|y|y|u|v
int yuv_buf_len = ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) * 6 ; // Y|u|v -> y|y|y|y|u|v
float * net_input_buf = get_buffer ( s - > net_input_buf , yuv_buf_len ) ;
float * net_input_buf = get_buffer ( s - > net_input_buf , yuv_buf_len ) ;
@ -128,7 +147,7 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_
//printf("preprocess completed. %d \n", yuv_buf_len);
//printf("preprocess completed. %d \n", yuv_buf_len);
//FILE *dump_yuv_file = fopen("/tmp/rawdump.yuv", "wb");
//FILE *dump_yuv_file = fopen("/tmp/rawdump.yuv", "wb");
//fwrite(raw_buf, height*width*3/2 , sizeof(uint8_t), dump_yuv_file);
//fwrite(resized_buf, yuv_buf_len , sizeof(uint8_t), dump_yuv_file);
//fclose(dump_yuv_file);
//fclose(dump_yuv_file);
// *** testing ***
// *** testing ***
@ -162,6 +181,7 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_
ret . partial_face = s - > output [ 35 ] ;
ret . partial_face = s - > output [ 35 ] ;
ret . distracted_pose = s - > output [ 36 ] ;
ret . distracted_pose = s - > output [ 36 ] ;
ret . distracted_eyes = s - > output [ 37 ] ;
ret . distracted_eyes = s - > output [ 37 ] ;
ret . occluded_prob = s - > output [ 38 ] ;
ret . dsp_execution_time = ( t2 - t1 ) / 1000. ;
ret . dsp_execution_time = ( t2 - t1 ) / 1000. ;
return ret ;
return ret ;
}
}
@ -188,6 +208,7 @@ void dmonitoring_publish(PubMaster &pm, uint32_t frame_id, const DMonitoringResu
framed . setPartialFace ( res . partial_face ) ;
framed . setPartialFace ( res . partial_face ) ;
framed . setDistractedPose ( res . distracted_pose ) ;
framed . setDistractedPose ( res . distracted_pose ) ;
framed . setDistractedEyes ( res . distracted_eyes ) ;
framed . setDistractedEyes ( res . distracted_eyes ) ;
framed . setOccludedProb ( res . occluded_prob ) ;
if ( send_raw_pred ) {
if ( send_raw_pred ) {
framed . setRawPredictions ( raw_pred . asBytes ( ) ) ;
framed . setRawPredictions ( raw_pred . asBytes ( ) ) ;
}
}