Commit b117ac95 authored by Ishankha K.C's avatar Ishankha K.C

use multiple devices

parent 7418010a
...@@ -4,10 +4,11 @@ import traceback ...@@ -4,10 +4,11 @@ import traceback
import cv2 import cv2
import numpy as np import numpy as np
import logging import logging
from fastapi import FastAPI, WebSocket from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from keras.models import load_model from keras.models import load_model
from keras.utils import img_to_array from keras.utils import img_to_array
import urllib.request import urllib.request
from urllib.error import URLError
# Configure logging # Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
...@@ -31,12 +32,13 @@ for class_name, index in class_indices.items(): ...@@ -31,12 +32,13 @@ for class_name, index in class_indices.items():
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
# Replace with your IP camera stream URL # Replace with your IP camera stream URL
url = 'http://192.168.1.7/cam-hi.jpg' base_dev_url = 'http://192.168.1.7/'
img_endpoint = '/cam-hi.jpg'
@app.websocket("/ws/emotion/{device_uid}")
@app.websocket("/ws/emotion") async def websocket_endpoint(websocket: WebSocket, device_uid: str):
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept() await websocket.accept()
url = base_dev_url+device_uid+img_endpoint
try: try:
while True: while True:
try: try:
...@@ -87,7 +89,8 @@ async def websocket_endpoint(websocket: WebSocket): ...@@ -87,7 +89,8 @@ async def websocket_endpoint(websocket: WebSocket):
"y": int(y), "y": int(y),
"width": int(w), "width": int(w),
"height": int(h) "height": int(h)
} },
"error": False
}) })
logging.info(f"Detected emotions: {emotions}") logging.info(f"Detected emotions: {emotions}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment