我正在尝试从 docker 容器运行 Python GUI 应用程序,但是当我尝试全屏显示时,什么都没有显示。如果我不打电话cv2.setWindowProperty("frame", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
,窗口会正常显示在屏幕上。
这是使用的 Dockerfile:
# syntax = docker/dockerfile:1.0-experimental
FROM arm64v8/debian:latest
RUN apt update && apt install -y \
ca-certificates \
gnupg \
curl
RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" \
| tee /etc/apt/sources.list.d/coral-edgetpu.list \
&& curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
RUN apt update && apt install -y \
python3 \
python3-pip \
python3-opencv \
python3-pycoral \
zlib1g-dev \
libjpeg-dev
RUN pip3 install \
v4l2 \
screeninfo \
pillo
这是脚本:
import cv2
import screeninfo
# Capture video from webcam
vid_capture = cv2.VideoCapture(1)
while True:
# Capture each frame of webcam video
screen = screeninfo.get_monitors()[0]
cv2.namedWindow("frame", cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow("frame", screen.x - 1, screen.y - 1)
cv2.setWindowProperty("frame", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
ret, frame = vid_capture.read()
cv2.imshow("frame", 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 window and de-allocate any associated memory usage
cv2.destroyAllWindows()
我正在使用以下docker run
命令:
docker run -d --rm \
--device /dev/apex_0:/dev/apex_0 \
--device /dev/video1:/dev/video1 \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix/:/tmp/.X11-unix \
guiapp bash
在运行容器之前,我确保环境配置了这些:
export DISPLAY=:0
xhost +
我想不出任何可能导致这种奇怪行为的东西。
编辑:经过进一步调查,我发现以root
.