-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeinVersuch.py
54 lines (42 loc) · 1.41 KB
/
meinVersuch.py
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
import time
import os
import numpy as np
import cv2
import pytesseract
# from imutils.video import VideoStream
# from imutils.video import FPS
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
def preprocessing(img):
img = cv2.medianBlur(img, 5)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1, 1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
# img = cv2.GaussianBlur(img, (5, 5), 0)
# img = cv2.medianBlur(img, 5)
img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
return img
def rescale_frame(frame, percent=75):
width = int(frame.shape[1] * percent / 100)
height = int(frame.shape[0] * percent / 100)
dim = (width, height)
return cv2.resize(frame, dim, interpolation=cv2.INTER_AREA)
# Check if the webcam is opened correctly
def show_webcam(mirror=False):
cam = cv2.VideoCapture(1 + cv2.CAP_DSHOW)
cam.set(3, 1920)
cam.set(4, 1080)
time.sleep(2)
while True:
ret_val, img = cam.read()
if mirror:
img = cv2.flip(img, 1)
img = preprocessing(img)
cv2.imshow('my webcam', rescale_frame(img))
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()
def main():
show_webcam(mirror=False)
if __name__ == '__main__':
main()