Vikas01 commited on
Commit
3e7017f
1 Parent(s): 02fac3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -65
app.py CHANGED
@@ -29,86 +29,86 @@ socket = SocketIO(app,async_mode="eventlet")
29
 
30
 
31
 
32
- def base64_to_image(base64_string):
33
- # Extract the base64 encoded binary data from the input string
34
- base64_data = base64_string.split(",")[1]
35
- # Decode the base64 data to bytes
36
- image_bytes = base64.b64decode(base64_data)
37
- # Convert the bytes to numpy array
38
- image_array = np.frombuffer(image_bytes, dtype=np.uint8)
39
- # Decode the numpy array as an image using OpenCV
40
- image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
41
- return image
42
-
43
- @socket.on("connect")
44
- def test_connect():
45
- print("Connected")
46
- emit("my response", {"data": "Connected"})
47
-
48
- @socket.on("image")
49
- def receive_image(image):
50
- global cnt
51
- s = True
52
- while s :
53
 
54
- # Decode the base64-encoded image data
55
- image = base64_to_image(image)
56
 
57
- known_faces_names = ["Sarwan Sir", "Vikas","Lalit","Jasmeen","Anita Ma'am"]
58
- known_face_encodings = []
59
 
60
- # Load known face encodings
61
- sir_image = face_recognition.load_image_file("photos/sir.jpeg")
62
- sir_encoding = face_recognition.face_encodings(sir_image)[0]
63
 
64
- vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
65
- vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
66
 
67
- lalit_image = face_recognition.load_image_file("photos/lalit.jpg")
68
- lalit_encoding = face_recognition.face_encodings(lalit_image)[0]
69
 
70
- jasmine_image = face_recognition.load_image_file("photos/jasmine.jpg")
71
- jasmine_encoding = face_recognition.face_encodings(jasmine_image)[0]
72
 
73
- maam_image = face_recognition.load_image_file("photos/maam.png")
74
- maam_encoding = face_recognition.face_encodings(maam_image)[0]
75
 
76
- known_face_encodings = [sir_encoding, vikas_encoding,lalit_encoding,jasmine_encoding,maam_encoding]
77
 
78
- students = known_faces_names.copy()
79
 
80
- face_locations = []
81
- face_encodings = []
82
- face_names = []
83
 
84
- # now = datetime.now()
85
- # current_date = now.strftime("%Y-%m-%d")
86
- # csv_file = open(f"{current_date}.csv", "a+", newline="")
87
 
88
- # # csv_writer = csv.writer(csv_file)
89
- small_frame = cv2.resize(image, (0, 0), fx=0.25, fy=0.25)
90
- rgb_small_frame = small_frame[:, :, ::-1]
91
- # # emit("result",{"name":"level " +str(cnt),"score":str(len(face_encodings))})
92
 
93
- face_locations = face_recognition.face_locations(rgb_small_frame)
94
- face_encodings = face_recognition.face_encodings(small_frame, face_locations)
95
- face_names = []
96
- emit("result",{"name":"level2 " +str(cnt),"score":str(len(face_encodings))})
97
- cnt = cnt +1
98
- for face_encoding in face_encodings:
99
- # emit("result",{"name":"in for ","score":"34"})
100
- matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
101
- name = ""
102
- face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
103
- best_match_index = np.argmin(face_distance)
104
- if matches[best_match_index]:
105
- name = known_faces_names[best_match_index]
106
 
107
- face_names.append(name)
108
- s = False
109
- break
110
 
111
- emit("result",{"name":str(name),"score":"myScore"})
112
 
113
 
114
 
 
29
 
30
 
31
 
32
+ # def base64_to_image(base64_string):
33
+ # # Extract the base64 encoded binary data from the input string
34
+ # base64_data = base64_string.split(",")[1]
35
+ # # Decode the base64 data to bytes
36
+ # image_bytes = base64.b64decode(base64_data)
37
+ # # Convert the bytes to numpy array
38
+ # image_array = np.frombuffer(image_bytes, dtype=np.uint8)
39
+ # # Decode the numpy array as an image using OpenCV
40
+ # image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
41
+ # return image
42
+
43
+ # @socket.on("connect")
44
+ # def test_connect():
45
+ # print("Connected")
46
+ # emit("my response", {"data": "Connected"})
47
+
48
+ # @socket.on("image")
49
+ # def receive_image(image):
50
+ # global cnt
51
+ # s = True
52
+ # while s :
53
 
54
+ # # Decode the base64-encoded image data
55
+ # image = base64_to_image(image)
56
 
57
+ # known_faces_names = ["Sarwan Sir", "Vikas","Lalit","Jasmeen","Anita Ma'am"]
58
+ # known_face_encodings = []
59
 
60
+ # # Load known face encodings
61
+ # sir_image = face_recognition.load_image_file("photos/sir.jpeg")
62
+ # sir_encoding = face_recognition.face_encodings(sir_image)[0]
63
 
64
+ # vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
65
+ # vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
66
 
67
+ # lalit_image = face_recognition.load_image_file("photos/lalit.jpg")
68
+ # lalit_encoding = face_recognition.face_encodings(lalit_image)[0]
69
 
70
+ # jasmine_image = face_recognition.load_image_file("photos/jasmine.jpg")
71
+ # jasmine_encoding = face_recognition.face_encodings(jasmine_image)[0]
72
 
73
+ # maam_image = face_recognition.load_image_file("photos/maam.png")
74
+ # maam_encoding = face_recognition.face_encodings(maam_image)[0]
75
 
76
+ # known_face_encodings = [sir_encoding, vikas_encoding,lalit_encoding,jasmine_encoding,maam_encoding]
77
 
78
+ # students = known_faces_names.copy()
79
 
80
+ # face_locations = []
81
+ # face_encodings = []
82
+ # face_names = []
83
 
84
+ # # now = datetime.now()
85
+ # # current_date = now.strftime("%Y-%m-%d")
86
+ # # csv_file = open(f"{current_date}.csv", "a+", newline="")
87
 
88
+ # # # csv_writer = csv.writer(csv_file)
89
+ # small_frame = cv2.resize(image, (0, 0), fx=0.25, fy=0.25)
90
+ # rgb_small_frame = small_frame[:, :, ::-1]
91
+ # # # emit("result",{"name":"level " +str(cnt),"score":str(len(face_encodings))})
92
 
93
+ # face_locations = face_recognition.face_locations(rgb_small_frame)
94
+ # face_encodings = face_recognition.face_encodings(small_frame, face_locations)
95
+ # face_names = []
96
+ # emit("result",{"name":"level2 " +str(cnt),"score":str(len(face_encodings))})
97
+ # cnt = cnt +1
98
+ # for face_encoding in face_encodings:
99
+ # # emit("result",{"name":"in for ","score":"34"})
100
+ # matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
101
+ # name = ""
102
+ # face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
103
+ # best_match_index = np.argmin(face_distance)
104
+ # if matches[best_match_index]:
105
+ # name = known_faces_names[best_match_index]
106
 
107
+ # face_names.append(name)
108
+ # s = False
109
+ # break
110
 
111
+ # emit("result",{"name":str(name),"score":"myScore"})
112
 
113
 
114