Pranav
Pranav

Reputation: 52

Python: Serial Transmission

I have an image stack of 500 images (jpeg) of 640x480. I intend to make 500 pixels (1st pixels of all images) as a list and then send that via COM1 to FPGA where I do my further processing.

I have a couple of questions here:

  1. How do I import all the 500 images at a time into python and how do i store it?
  2. How do I send the 500 pixel list via COM1 to FPGA?

I tried the following:

  1. Converted the jpeg image to intensity values (each pixel is denoted by a number between 0 and 255) in MATLAB, saved the intensity values in a text file, read that file using readlines(). But it became too cumbersome to make the intensity value files for all the 500 images!
  2. Used NumPy to put the read files in a matrix and then pick the first pixel of all images. But when I send it, its coming like: [56, 61, 78, ... ,71, 91].

Is there a way to eliminate the [ ] and , while sending the data serially?

Thanks in Advance! :)

Upvotes: 0

Views: 1038

Answers (1)

MartinStettner
MartinStettner

Reputation: 29164

Ad 1: Use a library like PIL for accessing the images. You can load an image using

from PIL import Image
im = Image.open("img000.jpg")

And access the first pixel value using

pixel = im.getpixel(0,0)

This returns a color tuple for the first pixel, you have to calculate the intensity from this.

Ad 2: This depends on how your FPGS expects the values? Since you mentioned eliminating [ , do you need a comma-separated ASCII string? Try

pixel_string = ','.join([str(x) for x in pixel_list])

If you need to send a series of bytes construct the byte string like

pixel_string = ''.join([chr(x) for x in pixel_list])

Both examples assume, that you have constructed you list of intensity values in pixel_list.

Upvotes: 3

Related Questions