-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIdentifying.py
78 lines (60 loc) · 1.78 KB
/
Identifying.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import cv2
import numpy as np
import os
from datetime import datetime
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
path = 'query'
orb = cv2.ORB_create(nfeatures=1000)
### Importing Images
images = []
classNames = []
myList = os.listdir(path)
# print(myList)
# print('Total Classes Detected', len(myList))
for cl in myList:
imgCur = cv2.imread(f'{path}/{cl}',0)
images.append(imgCur)
# print(cl)
classNames.append(os.path.splitext(cl)[0])
print(classNames)
def findDes(images):
desList = []
for img in images:
sp, des = orb.detectAndCompute(img, None)
desList.append(des)
return desList
def findID(img,desList):
kp2,des2 = orb.detectAndCompute(img, None)
bf = cv2.BFMatcher()
matchList=[]
finalvalue = -1
try:
for des in desList:
matches = bf.knnMatch(des, des2, k=2)
good = []
for m, n in matches:
if m.distance < 0.75 * n.distance:
good.append([m])
matchList.append(len(good))
print(matchList)
except:
pass
if len(matchList)!=0:
if max(matchList) > 16:
finalvalue = matchList.index((max(matchList)))
return finalvalue
desList = findDes(images)
# print(len(desList))
cap = cv2.VideoCapture(0)
print("SHOW ID")
while True:
success, img2 = cap.read()
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
id = findID(img2,desList)
if id !=-1:
cv2.putText(img2, classNames[id],(50,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255),2)
print("AIGHT YOU IS GOOD")
# findID(img2, desList)
cv2.imshow('Authentication', img2)
cv2.waitKey(1)