@ -114,6 +114,21 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_ 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                    resized_width ,  resized_height ,   
					 
					 
					 
					                    resized_width ,  resized_height ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                    mode ) ;   
					 
					 
					 
					                    mode ) ;   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  // prerotate to be cache aware
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  uint8_t  * resized_buf_rot  =  get_buffer ( s - > resized_buf_rot ,  resized_width * resized_height * 3 / 2 ) ;   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  uint8_t  * resized_y_buf_rot  =  resized_buf_rot ;   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  uint8_t  * resized_u_buf_rot  =  resized_y_buf_rot  +  ( resized_width  *  resized_height ) ;   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  uint8_t  * resized_v_buf_rot  =  resized_u_buf_rot  +  ( ( resized_width / 2 )  *  ( resized_height / 2 ) ) ;   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  libyuv : : I420Rotate ( resized_y_buf ,  resized_width ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                     resized_u_buf ,  resized_width / 2 ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                     resized_v_buf ,  resized_width / 2 ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                     resized_y_buf_rot ,  resized_height ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                     resized_u_buf_rot ,  resized_height / 2 ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                     resized_v_buf_rot ,  resized_height / 2 ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                     // negative height causes a vertical flip to match previous
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                     resized_width ,  - resized_height ,  libyuv : : kRotate90 ) ;   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  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 ) ;   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  // one shot conversion, O(n) anyway
   
					 
					 
					 
					  // one shot conversion, O(n) anyway
   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -121,17 +136,17 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_ 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  for  ( int  c  =  0 ;  c  <  MODEL_WIDTH / 2 ;  c + + )  {   
					 
					 
					 
					  for  ( int  c  =  0 ;  c  <  MODEL_WIDTH / 2 ;  c + + )  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    for  ( int  r  =  0 ;  r  <  MODEL_HEIGHT / 2 ;  r + + )  {   
					 
					 
					 
					    for  ( int  r  =  0 ;  r  <  MODEL_HEIGHT / 2 ;  r + + )  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      // Y_ul
   
					 
					 
					 
					      // Y_ul
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r ]  =  input_lambda ( resized_buf [ ( 2 * r * resized_width )  +  ( 2 * c ) ] ) ;   
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 0 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf_rot [ ( 2 * r )  +  ( 2 * c ) * resized_height ] ) ;   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      // Y_ur
   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 2 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf [ ( 2 * r * resized_width )  +  ( 2 * c + 1 ) ] ) ;   
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      // Y_dl
   
					 
					 
					 
					      // Y_dl
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf [ ( 2 * r * resized_width + 1 )  +  ( 2 * c ) ] ) ;   
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 1 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf_rot [ ( 2 * r + 1 )  +  ( 2 * c ) * resized_height ] ) ;   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      // Y_ur
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 2 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf_rot [ ( 2 * r )  +  ( 2 * c + 1 ) * resized_height ] ) ;   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      // Y_dr
   
					 
					 
					 
					      // Y_dr
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 3 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf [ ( 2 * r * resized_width + 1 )  +  ( 2 * c + 1 ) ] ) ;   
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 3 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf_rot  [ ( 2 * r + 1 )  +  ( 2 * c + 1 ) * resized_height ] ) ;   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      // U
   
					 
					 
					 
					      // U
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 4 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf [ ( resized_width * resized_height )  +  ( r * resized_width / 2 )  +  c ] ) ;   
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 4 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf_rot  [ ( resized_width * resized_height )  +  r  +  ( c * resized_height / 2 ) ] ) ;   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      // V
   
					 
					 
					 
					      // V
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 5 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf [ ( resized_width * resized_height )  +  ( ( resized_width / 2 ) * ( resized_height / 2 ) )  +  ( r * resized_width / 2 )  +  c ] ) ;   
					 
					 
					 
					      net_input_buf [ ( c * MODEL_HEIGHT / 2 )  +  r  +  ( 5 * ( MODEL_WIDTH / 2 ) * ( MODEL_HEIGHT / 2 ) ) ]  =  input_lambda ( resized_buf_rot  [ ( resized_width * resized_height )  +  ( ( resized_width / 2 ) * ( resized_height / 2 ) )  +  r  +  ( c * resized_height / 2 ) ] ) ;   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    }   
					 
					 
					 
					    }   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  }   
					 
					 
					 
					  }   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -140,6 +155,10 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_ 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  //fwrite(raw_buf, height*width*3/2, sizeof(uint8_t), dump_yuv_file);
   
					 
					 
					 
					  //fwrite(raw_buf, height*width*3/2, sizeof(uint8_t), dump_yuv_file);
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  //fclose(dump_yuv_file);
   
					 
					 
					 
					  //fclose(dump_yuv_file);
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  // *** testing ***
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  // idat = np.frombuffer(open("/tmp/inputdump.yuv", "rb").read(), np.float32).reshape(6, 160, 320)
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  // imshow(cv2.cvtColor(tensor_to_frames(idat[None]/0.0078125+128)[0], cv2.COLOR_YUV2RGB_I420))
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  //FILE *dump_yuv_file2 = fopen("/tmp/inputdump.yuv", "wb");
   
					 
					 
					 
					  //FILE *dump_yuv_file2 = fopen("/tmp/inputdump.yuv", "wb");
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  //fwrite(net_input_buf, MODEL_HEIGHT*MODEL_WIDTH*3/2, sizeof(float), dump_yuv_file2);
   
					 
					 
					 
					  //fwrite(net_input_buf, MODEL_HEIGHT*MODEL_WIDTH*3/2, sizeof(float), dump_yuv_file2);
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  //fclose(dump_yuv_file2);
   
					 
					 
					 
					  //fclose(dump_yuv_file2);