Read and save RGB Lossless Images from a OpenMV cam M7 .bin file

I have a raw_images.bin recorded using OpenMV cam M7 in a 8bit Bayer format. How can i read the raw images, convert to RGB and save them with lossless compression into my disk

Hi, see the IO reader example.

Then when you read a frame use the to_rgb565() method. Then, save the images as a BMP file.

You don’t want to try to save as PNG. That’s for graphics. JPEG is preferred but you said losses compression.

Hi Kwagyeman,

Thanks for the quick reply. I am sorry as I am very new to OpenMV I would need your help further.
So, basically I was able to find out that the below code from imageio_read…py may work to read the images from .bin file.

However, when i run this i get module ‘image’ has no attribute ‘ImageIO’.
How do i install image library correctly? Am I doing it right?

# import sensor, image, time
import image, time
# snapshot_source = False # Set to true once finished to pull data from sensor.
#
# sensor.reset()
# sensor.set_pixformat(sensor.RGB565)
# sensor.set_framesize(sensor.QQVGA)
# sensor.skip_frames(time = 2000)
clock = time.process_time()

stream = None

stream = image.ImageIO("./raw_images.bin", "r")

while True:
    clock.tick()
    img = stream.read(copy_to_fb=True, loop=True, pause=True)

    # Do machine vision algorithms on the image here.
    print(clock.fps())

You need to update your firmware.

Hi. I build the firmware linux build and was able to generate all the build artifacts. However, I still get the ‘image’ has no attribute ‘ImageIO’ error. I am not sure what image library it is importing.

# Image Reader Example
#
# USE THIS EXAMPLE WITH A USD CARD!
#
# This example shows how to use the Image Reader object to replay snapshots of what your
# OpenMV Cam saw saved by the Image Writer object for testing machine vision algorithms.

# Altered to allow full speed reading from SD card for extraction of sequences to the network etc. 
# Set the new pause parameter to false

import sensor, image, time

snapshot_source = False # Set to true once finished to pull data from sensor.

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

stream = None
if snapshot_source == False:
    stream = image.ImageIO("/stream.bin", "r")

while(True):
    clock.tick()
    if snapshot_source:
        img = sensor.snapshot() 
    else:
        img = stream.read(copy_to_fb=True, loop=True, pause=True)
    # Do machine vision algorithms on the image here.
    print(clock.fps())

This example works with the latest firmware. Not sure what issues you are having.

OSError: Could not find the file.
what is stream.bin file? can i change a jpeg file name for that?

You have to write the stream.bin file using the image writer example.

If you want to load jpegs just use the Image class constructor.

is there any example about image.image()?

jpg_image = image.Image("file.jpeg", copy_to_fb=True)
rgb565_img = jpg_image.to_rgb565()
1 Like