forked from te4-Leo-Wahlandt/PythonOpenCVExamen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (51 loc) · 1.55 KB
/
main.py
File metadata and controls
63 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
import cv2
import pytesseract
from PIL import Image
import os
import re
from scrapper import CheckifPolice
import time
import RPi.GPIO as GPIO
cap = cv2.VideoCapture(0)
try:
if not os.path.exists('data'):
os.makedirs('data')
except OSError:
print('Error Creating directory of data')
currentFrame = 0
#The LED response
#GPIO.setmode(GPIO.BCM)
#Green light
if(GPIO.setup(26, GPIO.OUT) == False):
GPIO.setup(26, GPIO.OUT)
#red light
if(GPIO.setup(6, GPIO.OUT) == False):
GPIO.setup(6, GPIO.OUT)
#This code will be able to load in the source code for the biluppgifter homepage
#Run program: python3 OCR.py
while(True):
#reset the GPIO
GPIO.setup(6, False)
GPIO.setup(26, False)
ret, video = cap.read()
cv2.imshow('video', video)
videoText = pytesseract.image_to_string(video, lang ='eng')
videoReg = re.findall("[A-Z]{3} [0-9]{2}[(0-9)|(A-Z)]{1}", videoText)
print(videoReg)
if (videoReg):
result = "".join(videoReg)
name = './data/frame' + str(currentFrame) + '.png'
cv2.imwrite(name, video)
print('creating...' + name)
imgText = pytesseract.image_to_string(name, lang ='eng')
imgReg = re.findall("[A-Z]{3} [0-9]{2}[(0-9)|(A-Z)]{1}", imgText)
resultImg = "".join(imgReg)
if (result == resultImg):
CheckifPolice(result)
else:
print("different values, video: " + result + " Result img: " + resultImg)
currentFrame += 1
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()