AL-2020/coder/image.py
2020-05-20 07:36:18 +02:00

32 lines
675 B
Python

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import cv2
def image():
img = cv2.cvtColor(cv2.imread('test.jpg'), cv2.COLOR_BGR2GRAY)
img = cv2.GaussianBlur(img, (15, 15), 0) # poprawia jakosc
img = cv2.resize(img, (8, 8), interpolation=cv2.INTER_AREA)
print(type(img))
print(img.shape)
print(img)
plt.imshow(img, cmap='binary')
plt.show()
data = []
rows, cols = img.shape
for i in range(rows):
for j in range(cols):
k = img[i, j]
if k > 200:
k = 0 # brak czarnego
else:
k = 1
data.append(k)
print(data)