-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.py
More file actions
35 lines (27 loc) · 1 KB
/
load.py
File metadata and controls
35 lines (27 loc) · 1 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
import pytesseract
import cv2
import os
from PIL import Image
global face_cascade
#from google.colab.patches import cv2_imshow
class ImageProcessing:
def __init__(self):
self.face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
def cropFace(self,img,gray):
faces = self.face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 0, 255), 2)
faces = img[y:y + h, x:x + w]
return faces
def scanId(self,img, id, name) :
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
filename = "{}.jpg".format(os.getpid())
cv2.imwrite(filename, gray)
text = pytesseract.image_to_string(Image.open(filename), lang = 'Hangul')
text = text.replace(" ", "") # 띄어쓰기 제거
os.remove(filename)
if str(id) in text or name in text :
#face = self.cropFace(img,gray)
return 1
else:
return -1