Reading sent image over Uart

Hi OpenMV People,

I was able to send and save an image from OpenMV to a Pycom board following OpenMV forums;

uart = UART(3, 115200, bits=8 , parity=None , timeout_char=2000)
img = img.compress(quality=10)
uart.write(img)

However, I have a hard time converting the saved image from Pycom flash memory to an image on my computer to check if it sent it correctly.
I found a base64 decode to image from this link: How to convert Byte Data to Image in Python (using Pillow library) - YouTube
Since Uart does not do base64 encoding mentioned in the video, I removed that part as follows and just tried to display it using imshow function; but it did not work;

import PIL.Image as Image
import io
from byte_array_fromOpenMV import byte_data
img = Image.open(byte_data)
img.show()

The start of OpenMV transmitted image looks like:

b’\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00\x00\x00\x00\x00\x00\xff\xfe\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xdb\x00C\x00P7<F<2PFAFZUP_x\xc8\x82xnnx\xf5\xaf\xb9\x91\xc8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x0b\x08\x00<\x00P\x01\x01\x11\x00\xff\xc4\x00\x1f\x00\x00\x01\x05\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\xff\xc4\x00\xb5\x10\x00\x02\x01\x03\x03\x02\x04\x03\x05\x05\x04\x04\x00\x00\x01}\x01\x02\x03\x00\x04\x11\x05\x12!1A\x06\x13Qa\x07"q\x142\x81\x91\xa1\x08#B\xb1\xc1\x15R\xd1\xf0$3br\x82\t\n\x16\x17\x18\x19\x1a%&’()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\x83…’

The Python Error in Computer;
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte

I am not sure what type the file transmitted is, it looks like it is a hex file, but I don’t know how to convert it back to an image!

Thank you in advance for your help!
MoZen

It’s a JPEG image, save it to file and open it.

1 Like

Thanks, yes eventually I realized it is JPEG.
I used ubinascii.b2a_base64(img.compress(quality=10)) to make it base64 encoding then decoded it using the mentioned code in the computer and got back the image.