Skip to content

Instantly share code, notes, and snippets.

@Namburger
Created November 19, 2020 15:26
Show Gist options
  • Save Namburger/b76f417a8e96052c7b78bcdbd824f57a to your computer and use it in GitHub Desktop.
Save Namburger/b76f417a8e96052c7b78bcdbd824f57a to your computer and use it in GitHub Desktop.
Minimal Dockerfile for Coral Dev Board with tflite API
FROM arm64v8/debian:latest
WORKDIR /home
ENV HOME /home
RUN cd ~
RUN apt-get update
RUN apt-get install -y git nano python3-pip python-dev pkg-config wget usbutils curl
RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" \
| tee /etc/apt/sources.list.d/coral-edgetpu.list
RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
RUN apt-get update
@alexcocinda
Copy link

That's awesome, thank you! I tried to read and display the stream from a usb webcam after running the container with a few extra options:
docker run -it --device /dev/apex_0:/dev/apex_0 --device /dev/bus/usb/:/dev/bus/usb -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix --name test coral /bin/bash.

But I get the following error:
cv2.error: /build/opencv-tragD2/opencv-3.2.0+dfsg/modules/highgui/src/window.cpp:304: error: (-215) size.width>0 && size.height>0 in function imshow

This is the script I used:

import cv2

#Capture video from webcam
vid_capture = cv2.VideoCapture(1)
vid_cod = cv2.VideoWriter_fourcc(*'XVID')
output = cv2.VideoWriter("videos/cam_video.mp4", vid_cod, 20.0, (640,480))

while(True):
     # Capture each frame of webcam video
     ret,frame = vid_capture.read()
     cv2.imshow("My cam video", frame)
     output.write(frame)
     # Close and break the loop after pressing "x" key
     if cv2.waitKey(1) &0XFF == ord('x'):
         break

# close the already opened camera
vid_capture.release()
# close the already opened file
output.release()
# close the window and de-allocate any associated memory usage
cv2.destroyAllWindows()

I also installed python3-opencv. Do you have any idea about what the problem could be?

@Namburger
Copy link
Author

@alexcocinda I'm not 100% sure, but according to this tutorial:
https://www.learnopencv.com/install-opencv-docker-image-ubuntu-macos-windows/

You may want to specify the video device file as oppose to the usb devide it self, maybe?

–device=/dev/video0:/dev/video0

@alexcocinda
Copy link

Yes, you are right, thank you. I'll continue to describe the following issue if someone else tries this too. After I fixed my docker run, I got the following error:

Unable to init server: Could not connect: Connection refused

(My cam video:12): Gtk-WARNING **: 18:54:45.068: cannot open display: :0

I managed to fix it by executing the following commands:

sudo apt install -y x11-xserver-utils
xhost +

make sure that DISPLAY is set correctly and check your display number with w. If it's not, try the following:

w
export DISPLAY=<number-you-found-from-the-w-command-output>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment