Converting a byte array into an image

Hi!
I’m receiving grayscale pixel data from a thermal sensor over the serial port. It is transferred into a byte array and I now want to transform it into an image via image.image() to combine it with the onboard camera module. The problem is that I always get the “TypeError: ‘arg’ argument required”. Do I miss something?

img = image.Image(width=width, height=height, pixel_format=image.GRAYSCALE, buffer=byte_array)

Thanks in advance :slightly_smiling_face:

img = image.Image(width, height, image.GRAYSCALE, buffer=byte_array)

The args aren’t keyword args in this case.

1 Like

Thanks :smile:

And as a follow up. :slightly_smiling_face:Is there a way to display an img in the IDE that isn’t the onboard camera snapshot? Like the image I created from external sensor data?

img = image.Image(width, height, image.GRAYSCALE, buffer=byte_array, copy_to_fb=True)
1 Like

Oh. :upside_down_face:I had already tried that, but always with an error message. I must have overlooked another error. Now it works. Great! Thank you very much! :smile:

Hi!
As another follow up. :slight_smile: As described, I’m using my rt1062 cam with an external thermal sensor. The problem I’m now facing is that the conversion of the serial data to an image is a bigger bottleneck than I anticipated and is somewhere around 3 fps for the conversion alone.

What would be the most efficient way of converting for maximizing frame rates?

My current approach looks like the following:
1. if uart.any():
num_bytes = uart.readinto(buffer)

2. convert pixel data to grayscale and to a bytearray

3 imgHTPA = image.Image(width, height, image.GRAYSCALE, buffer=byte_array, copy_to_fb=False)

I have seen that there is also a fir-function for a different sensor, is a similar approach used there?

Thank you in advance :slightly_smiling_face:

Your issue is step 1 and 2.

First, how fast are you receiving serial data? Second, how much data is there? If you’re trying to convert a 320x320 14-bit image to 8-bits grayscale or something using Python then this will be very slow.

If it’s an 8x8 thermal image then it would be fast.

What are the system parameters?

Sr. I forgot to add them :face_with_open_eyes_and_hand_over_mouth:
Serial runs at 2 000 000.
At the moment, the pixel data over serial are values in deciKelvin with 4 digits per pixel.
Overall it’s an image with 2400 pixels.

For the conversion to grayscale I take the temperature range of interest and simply map the data to values between 0 and 255.

2Mb/s is good. What’s the bus utilization through?

At the moment, the pixel data over serial are values in deciKelvin with 4 digits per pixel.

Yeah… that’s your problem. Probably want to send binary data. You’re running a rather large function to convert text to a binary value per pixel.

1 Like