def post(self): u = User() try: log.info("Inside create attendance method for student ----->>") azure_face_enabled = os.getenv("AZURE_FACE_ENABLED") aws_rekog_enabled = os.getenv("AWS_REKOG_ENABLED") facenet_enabled = os.getenv("FACENET_ENABLED") if azure_face_enabled is None: log.info("AZURE_FACE_ENABLED not set, falling back to config") azure_face_enabled = current_app.config["AZURE_FACE_ENABLED"] if aws_rekog_enabled is None: log.info("AWS_REKOG_ENABLED not set, falling back to config") aws_rekog_enabled = current_app.config["AWS_REKOG_ENABLED"] if facenet_enabled is None: log.info("FACENET_ENABLED not set, falling back to config") facenet_enabled = current_app.config["FACENET_ENABLED"] body = request.get_json() attendance = Attendance(**body) self.check_if_attendance_marked(attendance) school = check_school_active(attendance.school) check_module_active(attendance.moduleId, school.get("timeZone")) validateVicinity(body) user = u.fetchStudent(username=attendance.username) if str(facenet_enabled) == "1" and (user.get("imageId") is None or len(user.get("imageId")) < 1): attendance.recognitionSource = "facenet" attendance.recognitionConfidence = compare_faces_facenet( attendance.capturedImageId, attendance.username) else: if str(azure_face_enabled) == "1": attendance.recognitionSource = "azure" attendance.recognitionConfidence = compare_faces_azure( attendance.capturedImageId, user.get("imageId")[0]) if str(aws_rekog_enabled) == "1": attendance.recognitionSource = "aws" attendance.recognitionConfidence = compare_faces_rekognition( attendance.capturedImageId, user.get("imageId")[0]) attendance.save() publish_message(data=json.loads(attendance.to_json()), recorded=True) except Exception as ex: log.error("error from post attendance method " + str(ex)) return {"message": str(ex)}, 400 return {"id": str(attendance.id)}, 200
def videosplitter(key): try: # get SRS_CLUSTER URL from environment variable srs_cluster = os.getenv("SRS_CLUSTER") if srs_cluster is None: log.info("srs cluster not found in env") srs_cluster = config.Config.VIDEO_INPUT_PATH log.info("final srs cluster and key value is " + srs_cluster + key) cap = cv2.VideoCapture(srs_cluster + key) cap.open(srs_cluster + key) isCapOpen = cap.isOpened() log.info("cap is opened : " + str(isCapOpen)) currentFrame = 0 while cap.isOpened(): # Capture frame-by-frame ret, frame = cap.read() # Convert frames into base64 encoded string ret, buffer = cv2.imencode(".jpg", frame) imageData = base64.b64encode(buffer) # Publishing frames to kafka topic kafka_producer = connect_kafka_producer() publish_message(kafka_producer, config.Config.KAFKA_TOPIC, "frame", key, imageData) # Saves image of the current frame in jpg file name = "/frame" + str(currentFrame) + ".jpg" log.info("Creating..." + name) # To stop duplicate images currentFrame += 1 except Exception as ex: log.error("Exception while splitting video") log.error(str(ex)) finally: # When everything done, release the capture cap.release() cv2.destroyAllWindows()
def post(self): try: log.info("Inside create attendance method for student ----->>") body = request.get_json() attendance = Attendance(**body) self.check_if_attendance_marked(attendance) check_module_active(attendance.moduleId) validateVicinity(body) user = fetchUser(attendance.username) if user.get('imageId') is None: compare_faces_facenet(attendance.capturedImageId, attendance.username) else: compare_faces_rekognition(attendance.capturedImageId, user.get('imageId')[0]) attendance.save() publish_message(body) except Exception as ex: return {'message': str(ex)}, 400 return {'id': str(attendance.id)}, 200
def delete(self, id): log.info("Inside delete attendance method for student by id ---->>") try: u = User() username = request.headers.get("Username") if username is None: raise Exception("Username header missing in delete request") else: user = u.fetchAdmin(username=username) attendance = Attendance.objects.get(id=id) attendance.status = "REVOKED" attendance.save() publish_message( data={ "username": attendance.username, "revokedBy": username, "moduleId": attendance.moduleId, }, recorded=False, ) except Exception as ex: log.error("error from delete attendance method " + str(ex)) return {"message": str(ex)}, 400 return "", 200
def videosplitter(key): try: cap = cv2.VideoCapture(config.Config.VIDEO_INPUT_PATH + key) cap.open(config.Config.VIDEO_INPUT_PATH + key) isCapOpen = cap.isOpened() log.info('cap is opened : ' + str(isCapOpen)) currentFrame = 0 while cap.isOpened(): # Capture frame-by-frame ret, frame = cap.read() # Convert frames into base64 encoded string ret, buffer = cv2.imencode('.jpg', frame) imageData = base64.b64encode(buffer) # Publishing frames to kafka topic kafka_producer = connect_kafka_producer() publish_message(kafka_producer, config.Config.KAFKA_TOPIC, 'frame', key, imageData) # Saves image of the current frame in jpg file name = '/frame' + str(currentFrame) + '.jpg' log.info('Creating...' + name) # To stop duplicate images currentFrame += 1 except Exception as ex: log.error('Exception while splitting video') log.error(str(ex)) finally: # When everything done, release the capture cap.release() cv2.destroyAllWindows()