@@ -153,136 +153,6 @@ def train_classifier(cls):
153153 f .write (pickle .dumps (data ))
154154 f .close ()
155155
156- # def recognize_n_attendance_dnn(self):
157- # print("[INFO] loading encodings...")
158- # data = pickle.loads(open(ENCODINGS_FILE, "rb").read())
159- # # print(len(data['encodings']) == len(data['ids']))
160- #
161- # print("[INFO] starting video stream...")
162- # # store input video stream in cap variable
163- # cap = cv2.VideoCapture(self.input_video)
164- # # load our serialized model from disk
165- # net = cv2.dnn.readNetFromCaffe(prototxt=PROTOTXT_PATH, caffeModel=CAFFEMODEL_PATH)
166- #
167- # # find if today's attendance exists in the database
168- # attendance = AttendanceModel.find_by_date(date=dt.today())
169- # # if not
170- # if attendance is None:
171- # # create new instance for today's attendance
172- # attendance = AttendanceModel()
173- #
174- # # loop over the frames from the video stream
175- # while True:
176- # # grab the frame from the video stream
177- # ret, img = cap.read()
178- #
179- # # convert the input frame from BGR to RGB then resize it to have
180- # # a width of 750px (to speedup processing)
181- # rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
182- # # rgb = imutils.resize(img, width=750)
183- # r = img.shape[1] / float(rgb.shape[1])
184- #
185- # # grab the image frame dimensions and convert it to a blob
186- # (h, w) = img.shape[:2]
187- # blob = cv2.dnn.blobFromImage(
188- # cv2.resize(img, (300, 300)), 1.0, (300, 300), (104.0, 177.0, 123.0)
189- # )
190- #
191- # # pass the blob through the network and obtain the detections and
192- # # predictions
193- # net.setInput(blob)
194- # detections = net.forward()
195- #
196- # # loop over the detections
197- # for i in range(0, detections.shape[2]):
198- # # extract the confidence (i.e., probability) associated with the
199- # # prediction
200- # confidence = detections[0, 0, i, 2]
201- #
202- # # filter out weak detections by ensuring the `confidence` is
203- # # greater than the minimum confidence
204- # if confidence < 0.5:
205- # continue
206- #
207- # # compute the (x, y)-coordinates of the bounding box for the
208- # # object
209- # box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
210- # (startX, startY, endX, endY) = box.astype("int")
211- #
212- # # detect the (x, y)-coordinates of the bounding boxes
213- # # corresponding to each face in the input frame, then compute
214- # # the facial embeddings for each face
215- # boxes = [(startY, endX, endY, startX)]
216- #
217- # encodings = face_recognition.face_encodings(rgb, boxes)
218- # names = []
219- #
220- # # loop over the facial embeddings
221- # for encoding in encodings:
222- # # attempt to match each face in the input image to our known encodings
223- # matches = face_recognition.compare_faces(data["encodings"], encoding, DLIB_TOLERANCE)
224- # # name to be displayed on video
225- # display_name = "Unknown"
226- #
227- # # check to see if we have found a match
228- # if True in matches:
229- # # find the indexes of all matched faces then initialize a
230- # # dictionary to count the total number of times each face
231- # # was matched
232- # matched_indexes = [i for (i, b) in enumerate(matches) if b]
233- # counts = {}
234- #
235- # # loop over the matched indexes and maintain a count for
236- # # each recognized face
237- # for matched_index in matched_indexes:
238- # _id = data["ids"][matched_index]
239- # counts[_id] = counts.get(_id, 0) + 1
240- #
241- # # determine the recognized face with the largest number
242- # # of votes (note: in the event of an unlikely tie Python
243- # # will select first entry in the dictionary)
244- # _id = max(counts, key=counts.get)
245- # if _id:
246- # # find matched student in the database by id
247- # student = StudentModel.find_by_id(_id)
248- # # if student's attendance is not marked
249- # if not attendance.is_marked(student):
250- # # then mark student's attendance
251- # attendance.students.append(student)
252- # # commit changes to database
253- # attendance.save_to_db()
254- # # update displayed name to student's name
255- # display_name = student.name
256- # # append the name to be displayed in names list
257- # names.append(display_name)
258- # # loop over the recognized faces
259- # for ((top, right, bottom, left), display_name) in zip(boxes, names):
260- # if display_name == "Unknown":
261- # continue
262- # # rescale the face coordinates
263- # top = int(top * r)
264- # right = int(right * r)
265- # bottom = int(bottom * r)
266- # left = int(left * r)
267- # top_left = (left, top)
268- # bottom_right = (right, bottom)
269- #
270- # # draw the predicted face name on the image
271- # cv2.rectangle(img, top_left, bottom_right, (0, 255, 0), 2)
272- # y = top - 15 if top - 15 > 15 else top + 15
273- # cv2.putText(img, display_name, (left, y), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 0), 2)
274- #
275- # # display the output frames to the screen
276- # cv2.imshow(f"Recognizing Faces - {self.app_title}", img)
277- # k = cv2.waitKey(100) & 0xff # Press 'ESC' for exiting from the loop
278- # if k == 27:
279- # break
280- #
281- # # do a bit of cleanup
282- # cap.release()
283- # cv2.destroyAllWindows()
284- # print("Attendance Successful!")
285-
286156 def recognize_n_attendance (self ):
287157 print ("[INFO] loading encodings..." )
288158 data = pickle .loads (open (ENCODINGS_FILE , "rb" ).read ())
0 commit comments