Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: JPEG Compression for OV7670 images

  1. #1
    Senior Member
    Join Date
    Feb 2018
    Location
    Corvallis, OR
    Posts
    330

    JPEG Compression for OV7670 images

    I've downloaded a JPEG compression program and adapted it to run on the T4.1 to which I've connected my OV7670 camera. The original code used malloc() to allocate 256KB of buffers that hold pre-computed constants used during the compression. I moved these tables to arrays DMAMEM. The fact that DMAMEM doesn't get initialized is not an issue as an initialization function called from setup() fills the tables.

    The JPEG compressor needs an RGB888 bitmap as input. In the original code, the bitmap was read from a .BMP file. I changed the code to use a bitmap in EXTMEM as the input data.

    The process goes like this:

    * Capture a VGA-sized image to a buffer in EXTMEM. The image can be either RGB565 or YUV422 encoded. YUV images compress to smaller files due to the reduced spatial color resolution.

    * Use the Pixel Pipeline to convert the captured image from the original format to the RGB888 format the encoder wants. The converted image is now 921KB.

    * Call the JPG encoder with a pointer to the RGB888 buffer and a file name.

    * The encoder compresses the file and writes it to SD card with .jpg extension.

    An uncompressed VGA image in RGB565 format is 614KBytes. My compressed test images are about 40KBytes. Here is a test image:
    Click image for larger version. 

Name:	JP_12231320.jpg 
Views:	19 
Size:	42.4 KB 
ID:	22931

    The original 600KB RGB565 image is too large to upload to the forum which only allows .bmp files under 390KB in size.

    Compressing and writing a VGA image takes about 180MSec. The compression code first converts the RGB888 to YUV, then compresses the YUV data. Since the OV7670 can generate YUV images, I hope to eliminate the code and execution time needed to do the RGB888 to YUV conversion by having the compressor work directly on the YUV data from the camera. The compression code also writes the output to the SD card with one or two-byte writes. I hope to speed this up by writing the output to a buffer, then writing the full buffer to SD Card.

    I've got last-minute shopping and wrapping to do, so I probably won't post example code until the weekend.

  2. #2
    Senior Member
    Join Date
    Feb 2018
    Location
    Corvallis, OR
    Posts
    330
    After a bit more research on JPEG encoders, I found tooJpeg by Stephan Brumme. This encoder offered some significant advantages over the earlier version:

    1. No requirement for 256KB of precomputed lookup tables in DMAMEM.
    2. The ability to change the compression quality.
    3. Everything in one C++ file-----no includes or other libraries required.

    I modified this file to allow it to accept YCbCr images generated by the OV7670 camera, thus avoiding the necessity to convert the camera RGB565 or YUV422 image to RGB888 in an EXTMEM buffer. This eliminated about 100mSec. of conversion time and the need for a 921KB EXTMEM buffer to hold the VGA image. You do still need a 614KB buffer for a VGA YUV image.

    This JPEG converter can be found at https://github.com/mjborgerson/TooJpeg-Teensy4.1

    There are other repositories in my github for the OV7670 library, the PXP library, the command processor and the generic data logger. All of these are works in progress, so let me know if you have problems with the libraries or exampled.

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,873
    Sounds like some nice progress on this. May have to play again with this!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •