import cv2 class VideoCamera: def __init__(self, camera_type='user'): self.video = cv2.VideoCapture(0) # Default to webcam for testing self.camera_type = camera_type def __del__(self): self.video.release() def get_frame(self): success, image = self.video.read() if success: ret, jpeg = cv2.imencode('.jpg', image) return jpeg.tobytes() return None def switch_camera(self, camera_type): self.video.release() self.camera_type = camera_type self.video = cv2.VideoCapture(0) # Update for browser-based switching in JS