Please helpp, I am dockerizing my Flask app along with OpenCV for my web based project, however I cant access the camera, I can access it in localhost, but when i try to docker run, it keeps showing this error in terminal:
[ERROR:0@7.485] global cap.cpp:164 open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.9.0) /io/opencv/modules/videoio/src/cap_images.cpp:300: error: (-215:Assertion failed) !_filename.empty() in function 'open'
I have tried multiple solutions:
- Specifying the device:
docker run -it --device /dev/video0 ...
docker: Error response from daemon: error gathering device information while adding custom device “/dev/video0”: not a device node.
-
Giving privileged access and mounting /dev to access all the devices:
docker run -it --privileged -v /dev:/dev ...
-
Specifying cap = cv2.VideoCapture(‘/dev/video0’), when I try to print(cap), it does print a device:
cap: < cv2.VideoCapture 0x7fe470406cf0>
, however still it doesnt work, it cant access my camera
Below is my Dockerfile:
FROM python:3.8
RUN apt-get update && \
apt-get install -y libgl1-mesa-glx && \
pip install opencv-python && \
pip install Flask && \
pip install Flask-WTF && \
pip install ultralytics && \
pip install numpy && \
pip install pillow && \
pip install mediapipe && \
pip install scikit-learn
WORKDIR /app
COPY . /app
CMD ["python", "app.py"]