I’m currently converting a Python Tkinter GUI application into a web app with a Flask backend, React frontend, and real-time communication using Socket.IO.
The application is a digital microscope that captures images using OpenCV by setting specific camera properties. The captured images are then processed using PyTorch and other libraries.
In transitioning to a web app, I’m facing a challenge: the camera will be on the client side, so opencv.VideoCapture() won’t be able to access the client’s hardware directly.
Here’s a snippet of the code I use to adjust the camera properties and capture images in NumPy format:
cam = cv2.VideoCapture(camera_port, cv2.CAP_DSHOW)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, x_res_.value)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, y_res_.value)
# Set camera properties
cam.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG"))
cam.set(cv2.CAP_PROP_EXPOSURE, exposure.value) # -8
cam.set(cv2.CAP_PROP_GAIN, gain.value) # 1.0
I’m looking for a way to adjust these camera settings directly from the frontend (i.e., in the browser), capture the image, and then send it to the backend in the same NumPy format that OpenCV uses.
How can I overcome this technical issue? Any advice or guidance would be greatly appreciated. I’m really stuck here.
I tried capturing the image from frontend using react-webcam package and send image to backend and then process it, but I want it in the way thats being done in my gui application i.e. adjusting the cam properties firstly then capturing image and processing it, as its already in numpy format.
Abdullah Ashraf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1