@@ -484,54 +484,27 @@ impl BaseTransformImpl for EdgeImpulseVideoInfer {
484484 }
485485 } ;
486486
487- // Convert frame data to features based on channel count and input format
488- let features = if channels == 3 {
489- if format == Some ( VideoFormat :: Gray8 ) {
490- // Convert grayscale to RGB features
491- let mut features = Vec :: with_capacity ( ( width * height) as usize ) ;
492- for & gray in frame_data {
493- // Pack grayscale value into RGB format
494- let packed = ( gray as u32 ) << 16 | ( gray as u32 ) << 8 | ( gray as u32 ) ;
495- features. push ( packed as f32 ) ;
496- }
497- features
498- } else {
499- // RGB: Pack RGB values into single numbers
500- let mut features = Vec :: with_capacity ( ( width * height) as usize ) ;
501- for chunk in frame_data. chunks_exact ( 3 ) {
502- if let [ r, g, b] = chunk {
503- // Pack RGB values into a single number: (r << 16) + (g << 8) + b
504- let packed = ( * r as u32 ) << 16 | ( * g as u32 ) << 8 | ( * b as u32 ) ;
505- features. push ( packed as f32 ) ;
506- }
507- }
508- features
487+ // Always pass in full RGB array in the form of pixels like 0xff0000
488+ // DSP handles normalization and splitting into 1 or 3 channels
489+ let mut features = Vec :: with_capacity ( ( width * height) as usize ) ;
490+
491+ if format == Some ( VideoFormat :: Gray8 ) {
492+ // For grayscale images, create RGB values by repeating the grayscale value
493+ for & pixel in frame_data {
494+ // Create 24-bit RGB value: 0xRRGGBB where R=G=B=pixel
495+ let feature = ( ( pixel as u32 ) << 16 ) | ( ( pixel as u32 ) << 8 ) | ( pixel as u32 ) ;
496+ features. push ( feature as f32 ) ;
509497 }
510498 } else {
511- // Grayscale model: Convert input to grayscale if needed
512- let mut features = Vec :: with_capacity ( ( width * height) as usize ) ;
513- if format == Some ( VideoFormat :: Gray8 ) {
514- // Already grayscale, just pack the values
515- for & gray in frame_data {
516- let packed = ( gray as u32 ) << 16 | ( gray as u32 ) << 8 | ( gray as u32 ) ;
517- features. push ( packed as f32 ) ;
518- }
519- } else {
520- // Convert RGB to grayscale and pack
521- for chunk in frame_data. chunks_exact ( 3 ) {
522- if let [ r, g, b] = chunk {
523- // Convert RGB to grayscale using standard weights
524- let gray = ( 0.299 * ( * r as f32 )
525- + 0.587 * ( * g as f32 )
526- + 0.114 * ( * b as f32 ) ) as u8 ;
527- // Pack grayscale value into RGB format
528- let packed = ( gray as u32 ) << 16 | ( gray as u32 ) << 8 | ( gray as u32 ) ;
529- features. push ( packed as f32 ) ;
530- }
499+ // For RGB images, combine channels into 24-bit RGB values
500+ for chunk in frame_data. chunks_exact ( 3 ) {
501+ if let [ r, g, b] = chunk {
502+ // Create 24-bit RGB value: 0xRRGGBB
503+ let feature = ( ( * r as u32 ) << 16 ) | ( ( * g as u32 ) << 8 ) | ( * b as u32 ) ;
504+ features. push ( feature as f32 ) ;
531505 }
532506 }
533- features
534- } ;
507+ }
535508
536509 // Run inference
537510 let start = std:: time:: Instant :: now ( ) ;
@@ -625,7 +598,7 @@ impl BaseTransformImpl for EdgeImpulseVideoInfer {
625598 y : y as u32 ,
626599 width : width as u32 ,
627600 height : height as u32 ,
628- label : format ! ( "{:.3}" , value ) ,
601+ label : format ! ( "{value :.3}" ) ,
629602 } ) ;
630603 }
631604 }
0 commit comments