-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPRTT.py
67 lines (52 loc) · 2.23 KB
/
RPRTT.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
import tensorflow as tf
import keras
import os
import matplotlib as plt
import numpy as np
import random
import RealProject
from RealProject import *
from RPTraining import *
from RPEvaluation import *
from keras.metrics import Precision, Recall
import cv2
import app_data
from app_data import verify_image
#Verification backbone right here
app_data/verify_image
os.listdir(os.path.join('app_data', 'verify_image'))
os.path.join('app_data', 'input_image', 'input_image.jpg')
for image in os.listdir(os.path.join('app_data', 'verify_image')):
validation_img = os.path.join('app_data', 'verify_image', image )
print(validation_img)
def verify(model, detection_threshold, verification_threshold):
# Build results array
results = []
for image in os.listdir(os.path.join('app_data', 'verify_image')):
input_img = preprocess(os.path.join('app_data', 'input_image', 'input_image.jpg'))
validation_img = preprocess(os.path.join('app_data', 'verify_image', image))
# Make Predictions
result = model.predict(list(np.expand_dims([input_img, validation_img], axis=1)))
results.append(result)
# Detection Threshold: Metric above which a prediciton is considered positive
detection = np.sum(np.array(results) > detection_threshold)
# Verification Threshold: Proportion of positive predictions / total positive samples
verification = detection / len(os.listdir(os.path.join('app_data', 'verify_image')))
verified = verification > verification_threshold
return results, verified
#OPEN CV INCOMING
cap = cv2.VideoCapture(4)
while cap.isOpened():
ret, frame = cap.read()
frame = frame[120:120+250,200:200+250, :]
cv2.imshow('Verification', frame)
if cv2.waitKey(10) & 0xFF == ord('v'):
#This part will be modified with the xml file for the haar cascade to detect then do the siamese model.
cv2.imwrite(os.path.join('app_data', 'input_image', 'input_image.jpg'), frame)
# Run verification
results, verified = verify(siamese_model, 0.5, 0.5)
print(verified)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()