четверг, 8 апреля 2021 г.

Display binary data from CCS containing RGB-image in python matplotlib

How to get byte data from Code Composer Studio showed here (10.). Now we have a frame.bin, containg picture bytes.

1. Setup python 3, pip and matplotlib in windows:
1) download python3 from here, install
2) download get-pip.py from here to some local dir (in my case, ctrl-c in chrome and make a new text file get-pip.py in C:\Distrib\Python), install pip (type in cmd):

cd C:\Distrib\Python
python get-pip.py

3) to install matplotlib you need to open cmd and type:

python -m pip install -U matplotlib

2. Read frame.bin file with numpy.fromfile.

Do in cmd:
python
>>> import numpy as np
>>> img = np.fromfile("frame.bin",dtype='uint8')
>>> re_img = np.reshape(img[:388800],(540,720))

Matplotlib doc:
1) imread - reads png-file:
2) imshow - show numpy array:

Error showing grayscale image as colored:

Do in cmd:
python
>>> import matplotlib.pyplot as plt
>>> plt.imshow(re_img, cmap='gray')
>>> plt.show()

Result script:
python
>>> import numpy as np
>>> img = np.fromfile("frame.bin",dtype='uint8')
>>> re_img = np.reshape(img[:388800],(540,720))
>>> import matplotlib.pyplot as plt
>>> plt.imshow(re_img, cmap='gray')
>>> plt.show()

Комментариев нет:

Отправить комментарий