Cant access Camera on Docker Windows (OpenCV)

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:

  1. 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.

  1. Giving privileged access and mounting /dev to access all the devices: docker run -it --privileged -v /dev:/dev ...

  2. 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"]

Since Docker Desktop runs everything in a virtual machine (WSL2 or HyperV) you can’t just mount a camera device. There is GPU support because WSL2 supports GPU, so you could look for a solution for WSL2. You can check this for example

But I don’t really use Windows for Docker, so I can’t give you better ideas. And even if WSL2 supports something, it doesn’t neccessarily mean Docker Desktop can work with it too.