Spaces:
Sleeping
Sleeping
Fedgo29 commited on
Commit ·
32a4579
1
Parent(s): fc04bc0
Adding changes by Fedgo 25-6-2025 11:23 PM
Browse filesFiles changed (4)
185 unmodified lines18618718818919019119210 unmodified lines203204205206207208209185 unmodified lines@app.route('/frame/<int:cam_id>', methods=['GET'])def get_frame(cam_id):global cameras, fall_detector_core, cameras_ready, email_actual_userwait_time = 0while not cameras_ready and wait_time < 5:10 unmodified linesif not cap.isOpened():return jsonify({"error": "La cámara no está abierta"}), 500frame = fall_detector_core.process_frame(cap, email_actual_user, cam_id)if frame is None or frame.size == 0:frame = np.zeros((480, 640, 3), dtype=np.uint8)185 unmodified lines18618718818919019119210 unmodified lines203204205206207208209185 unmodified lines@app.route('/frame/<int:cam_id>', methods=['GET'])def get_frame(cam_id):global cameras, fall_detector_core, cameras_ready, email_actual_user, id_userwait_time = 0while not cameras_ready and wait_time < 5:10 unmodified linesif not cap.isOpened():return jsonify({"error": "La cámara no está abierta"}), 500frame = fall_detector_core.process_frame(cap, email_actual_user, cam_id, id_user)if frame is None or frame.size == 0:frame = np.zeros((480, 640, 3), dtype=np.uint8)
100 unmodified lines10110210310410510610710810928 unmodified lines13813914014114214314414514676 unmodified lines22322422522622722822923023135 unmodified lines267268269270271272273122 unmodified lines3963973983994004014024034044058 unmodified lines414415416417418419420421422100 unmodified linesexcept Exception as e:print("Error inesperado:", e)def setfalllogtoDB(self, resident_id, email: str, precision_value, cam_id: int):try:usuario_id = self.getLastSessionOfActualUser(email)fecha_hora_ingreso = datetime.now()ubicacion = "No especificada"detectado_por = "Sistema"28 unmodified linesexcept Exception as e:print("Error inesperado:", e)def setResidentToDB(self, residente_id, nombre, edad, genero, habitacion, color_de_ropa, email: str, id_camera: int):try:usuario_id = self.getLastSessionOfActualUser(email)fecha_ingreso = datetime.now().strftime("%Y-%m-%d %H:%M:%S")if usuario_id is None:print("No se encontró una sesión activa para el usuario con ese email.")76 unmodified linesprint("❌ Error inesperado en get_db_lastcamera:", e)return 0def setnotificationlogtoDB(self, email: str, resident_id, id_camara: int):try:usuario_id = self.getLastSessionOfActualUser(email)titulo = "Caída detectada"mensaje = "Se detectó una caída"caida_id = self.getfallIdDB(email)35 unmodified lines"""return np.array([lm.x, lm.y, lm.z])def process_frame(self, cap, email: str, cam_id: int):pid = 0#Procesa un frame de video, detecta personas, estima pose y evalúa caídas.ret, frame = cap.read()122 unmodified linesself.people[pid]["fall_time"] = time.time()self.people[pid]["fall_detected"] = Trueif(not self.getCheckResidentInDB(pid)):self.setResidentToDB(pid, "No definido", 0, "No definido", "No definida", "No definida", email, cam_id)#self.setlogtoDB(pid, "Not set yet", email)self.setfalllogtoDB(pid, email, prediction)self.setnotificationlogtoDB(email, pid, id_camara= cam_id)else:self.people[pid]["fall_detected"] = Falseself.people[pid]["fall_time"] = None8 unmodified linesif elapsed_time >= 1:self.setfalsesToDB("Falso Negativo", prediction, email)if(self.getCheckResidentInDB(pid)):self.setnotificationlogtoDB(email, pid, id_camara= cam_id)else:if self.people[pid]["fall_detected"]:self.setfalsesToDB("Falso Positivo", prediction, email)return frame100 unmodified lines10110210310410510610710810928 unmodified lines13813914014114214314414514676 unmodified lines22322422522622722822923023135 unmodified lines267268269270271272273122 unmodified lines3963973983994004014024034044058 unmodified lines414415416417418419420421422423424100 unmodified linesexcept Exception as e:print("Error inesperado:", e)def setfalllogtoDB(self, resident_id, email: str, precision_value, cam_id: int, user_id: int):try:usuario_id = user_id #self.getLastSessionOfActualUser(email)fecha_hora_ingreso = datetime.now()ubicacion = "No especificada"detectado_por = "Sistema"28 unmodified linesexcept Exception as e:print("Error inesperado:", e)def setResidentToDB(self, residente_id, nombre, edad, genero, habitacion, color_de_ropa, email: str, id_camera: int, id_user: int):try:usuario_id = id_user #self.getLastSessionOfActualUser(email)fecha_ingreso = datetime.now().strftime("%Y-%m-%d %H:%M:%S")if usuario_id is None:print("No se encontró una sesión activa para el usuario con ese email.")76 unmodified linesprint("❌ Error inesperado en get_db_lastcamera:", e)return 0def setnotificationlogtoDB(self, email: str, resident_id, id_camara: int, user_id):try:usuario_id = user_id#self.getLastSessionOfActualUser(email)titulo = "Caída detectada"mensaje = "Se detectó una caída"caida_id = self.getfallIdDB(email)35 unmodified lines"""return np.array([lm.x, lm.y, lm.z])def process_frame(self, cap, email: str, cam_id: int, user_id: int):pid = 0#Procesa un frame de video, detecta personas, estima pose y evalúa caídas.ret, frame = cap.read()122 unmodified linesself.people[pid]["fall_time"] = time.time()self.people[pid]["fall_detected"] = Trueif(not self.getCheckResidentInDB(pid)):self.setResidentToDB(pid, "No definido", 0, "No definido", "No definida", "No definida", email, cam_id, id_user=user_id)#self.setlogtoDB(pid, "Not set yet", email)self.setfalllogtoDB(pid, email, prediction, cam_id, user_id)self.setnotificationlogtoDB(email, pid, id_camara= cam_id, user_id=user_id)else:self.people[pid]["fall_detected"] = Falseself.people[pid]["fall_time"] = None8 unmodified linesif elapsed_time >= 1:self.setfalsesToDB("Falso Negativo", prediction, email)if(self.getCheckResidentInDB(pid)):self.setfalllogtoDB(pid, email, prediction, cam_id, user_id)self.setnotificationlogtoDB(email, pid, id_camara= cam_id, user_id=user_id)else:if self.people[pid]["fall_detected"]:self.setfalllogtoDB(pid, email, prediction, cam_id, user_id)self.setfalsesToDB("Falso Positivo", prediction, email)return frame
123version https://git-lfs.github.com/spec/v1oid sha256:5e77828de1723ff7e69172ba5672337ab10920379ce9b232abf288425eff90basize 53248123version https://git-lfs.github.com/spec/v1oid sha256:72f8dddaf85f0e7f521b31bcbe88b80c45a8227b82e567258b6029a689c003f5size 73728
app.py+2-2
core/__pycache__/fall_detector_core.cpython-310.pyc
core/fall_detector_core.py+13-11
guardiancare.db+2-2