Page 274 - MDP2020-1
P. 274
| 인천전자마이스터고등학교 ·············································································································
268
img_result = cv2.GaussianBlur(img_result, ksize=(3, 3), sigmaX=0)
_, img_result = cv2.threshold(img_result, thresh=0.0, maxval=255.0,
type=cv2.THRESH_BINARY | cv2.THRESH_OTSU)
img_result = cv2.copyMakeBorder(img_result, top=10, bottom=10, left=10, right=10,
borderType=cv2.BORDER_CONSTANT, value=(0,0,0))
chars = pytesseract.image_to_string(img_result, lang='kor', config='--psm 7 --oem 0')
result_chars = ''
has_digit = False
for c in chars:
if ord('가') <= ord(c) <= ord('힣') or c.isdigit():
if c.isdigit():
has_digit = True
result_chars += c
print(result_chars)
plate_chars.append(result_chars)
if has_digit and len(result_chars) > longest_text:
longest_idx = i
plt.subplot(len(plate_imgs), 1, i+1)
plt.imshow(img_result, cmap='gray')
info = plate_infos[longest_idx]
chars = plate_chars[longest_idx]
print(chars)
img_out = img_ori.copy()
cv2.rectangle(img_out, pt1=(info['x'], info['y']), pt2=(info['x']+info['w'], info['y']+info['h']),
color=(255,0,0), thickness=2)
cv2.imwrite(chars + '.jpg', img_out)
plt.figure(figsize=(12, 10))
plt.imshow(img_out)
plt.savefig('number.jpg')
<button_camera> // 압력 센서 누르면 카메라 촬영
from picamera import PiCamera
from time import sleep
from datetime import datetime
from gpiozero import Button
button = Button(18)
camera = PiCamera()
camera.resolution = (1024, 768)
while True: