JPEG Decoding with Portenta Vision Shield

So i got a Portenta H7 combined with a Portenta Vision Shield.
I would like to take a picture with the Vision Shield Camera and decode it with the integrated hardware decoder. I need to do this in the arduino ide 2.0.
My project is based on the CameraCaptureRawBytes Example from the Portenta library:

#include "camera.h"

CameraClass cam;
uint8_t fb[320 * 240];
uint8_t fb2[320 * 240];
JPEG_HandleTypeDef hjpeg;
JPEG_ConfTypeDef jpegConf;

void setup() {

  jpegConf.ColorSpace = JPEG_GRAYSCALE_COLORSPACE;

  hjpeg.Instance = JPEG;
  hjpeg.Conf = jpegConf;

  HAL_JPEG_Init(&hjpeg);
  Serial.begin(921600);

  // Init the cam QVGA, 30FPS
  cam.begin(CAMERA_R320x240, 30);
}

void loop() {
  // Wait until the receiver acknowledges
  // that they are ready to receive new data
  //while (Serial.read() != 1) {};

  // Grab frame and write to serial
  if (cam.grab(fb) == 0) {
    HAL_JPEG_Decode(&hjpeg, fb, (uint32_t)(320 * 240), fb2, (uint32_t)(320 * 240), HAL_MAX_DELAY);
    HAL_JPEG_GetInfo(&hjpeg, &jpegConf);
    Serial.println(jpegConf.ImageHeight);
    //Serial.write(fb, 320 * 240);
  }
}

Basically i test if it works by printing the received Image Height.

My problem right now is that my code never gets out of the HAL_JPEG_Decode function.
For testing i printed the hjpeg.State before the decoding and it returned 1, which corresponds to the ready state.
If i set the Timeout to 0 i dont get stuck anymore bc it gets thrown out by the timeout check inside the HAL_JPEG_Decode function.
I assume i get stuck in the while loop right after the timeout check.

FYI the Camera Outputs a Grayscale picture and i have absolutely no clue if my configurations and picture sizes are right.
You can look at the Hal_JPEG source code here: STM32CubeH7/stm32h7xx_hal_jpeg.c at master · STMicroelectronics/STM32CubeH7 · GitHub

1 Like

Hey Chris, you are correct in thinking that the camera outputs a grayscale picture. But it is not JPEG compressed, it is just raw bytes.

Yeah i already know that. In fact i asked to delete the question bc of that fact. However, i managed to decode jpeg from a sdcard.
Still thanks

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.