Last active
May 23, 2024 22:37
-
-
Save enric1994/7ab05985f775cb2954de6c30b72b07f9 to your computer and use it in GitHub Desktop.
Using the webcam in a GPU enabled Docker Compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
video_capture = cv2.VideoCapture(0) | |
anterior = 0 | |
while True: | |
if not video_capture.isOpened(): | |
print('Unable to load camera. Use the command "xhost +"') | |
pass | |
# Capture frame-by-frame | |
ret, frame = video_capture.read() | |
# Display the resulting frame | |
cv2.imshow('Video', frame) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
# Display the resulting frame | |
cv2.imshow('Video', frame) | |
# When everything is done, release the capture | |
video_capture.release() | |
cv2.destroyAllWindows() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2.3' | |
services: | |
webcam: | |
image: webcam | |
container_name: webcam | |
working_dir: /webcam | |
build: | |
context: . | |
dockerfile: Dockerfile.webcam | |
environment: | |
- DISPLAY=unix$DISPLAY | |
volumes: | |
- ./:/webcam | |
- /dev/video0:/dev/video0 | |
- /tmp/.X11-unix:/tmp/.X11-unix | |
command: bash -c "nvidia-smi && python -u camera.py" | |
privileged: true | |
runtime: nvidia |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM tensorflow/tensorflow:latest-gpu-py3 | |
RUN apt update -y && apt install -y \ | |
libsm6 \ | |
libxext6 \ | |
libxrender-dev | |
RUN pip install \ | |
opencv-python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment