Converting from JPEG coded byte array to EI Image format

Hi everyone,

I’m currently working on implementing an Image Classifier model in an STM32F767 Nucleo board. I’m using a VC0706 camera, and I communicate with the camera through UART in order to take a picture. The format in which I’m getting this picture is JPEG, I’m trying to decode this format and convert it to the one used when running the impulse ( locally on my STM32 using CubeIDE.

I understand that I should set the features array with the correct format of my image. However, I’m not really sure how to do this. I’m thinking I could use the JPEG peripheral to decode my image, or maybe should I use another library such as LIBJPEG. I have also seen that EI uses an RGB888 format, but it still isn’t very clear to me how it is expected to get to that final format.

Thanks ahead!

Hello @alejandroariasz,

Yes you need to use RGB888 format with EI run_classifier function (with the right dimensions).
I haven’t tried any project on images classification with STM32 boards yet so I do not have a code sample to provide but you can have a look at this article which will give a hint on how to convert jpeg to RGB888 using libjpeg library:

And so you can understand how each pixels are stored:

RGB888 is stored with unsigned int 32 bits

0	0	0	0	0	0	0	0	R7	R6	R5	R4	R3	R2	R1	R0	G7	G6	G5	G4	G3	G2	G1	G0	B7	B6	B5	B4	B3	B2	B1	B0



1 Like

Just to add to Louis excellent answer (be sure to pay close attention to the bitmap he provided, note the byte order and padding byte), you can also check if your conversion is correct by

  1. Upload your jpeg into studio
  2. Find that image and find “Raw features” (for example, on the “Image” page):image
  3. Make sure that your conversion matches that very closely (depending on your JPEG decoder, you might notice ±1 bit in each color channel)
  4. Also, when you invoke the classifier, you’ll want to implement a function that converts into a float array that the classifier expects (should match “Processed Features” in Studio), see for an example