简体   繁体   English

cv2.VideoCapture在docker容器中不起作用

[英]cv2.VideoCapture doesn't work within docker container

I am trying to use cv2.VideoCapture to capture image from a docker container. 我正在尝试使用cv2.VideoCapture从docker容器中捕获图像。

import cv2 vid = cv2.VideoCapture('path\\to\\video') ret, frame = vid.read()

In terms of the video file, I have tried either mount the file with docker -v or docker cp to copy the video file into container, but both with no luck (ret returns False). 就视频文件而言,我尝试使用docker -vdocker cp挂载文件将视频文件复制到容器中,但两者都没有运气(ret返回False)。

Should I add any command when launching the container? 我应该在启动容器时添加任何命令吗? Thanks in advance. 提前致谢。

There might be 2 problems: 可能有两个问题:

1) In your container opencv is not installed properly. 1)在您的容器中,opencv未正确安装。 To check that do print(ret, frame). 检查是否打印(ret,frame)。 If they come (false, None). 如果他们来(假,没有)。 Then opencv has not installed properly. 然后opencv没有正确安装。

2) The file you are using is corrupted. 2)您使用的文件已损坏。 To check that try to copy any image file (jpg) into the container and use cv2.imread to read the image and then print it. 要检查是否尝试将任何图像文件(jpg)复制到容器中并使用cv2.imread读取图像然后打印它。 If numpy array comes then while copying your file is not getting corrupted. 如果numpy数组出现,那么复制文件时不会损坏。

The best option is pull any opencv + python image and then create a container with it. 最好的选择是拉任何opencv + python图像,然后用它创建一个容器。 The better option is use dockerfiles of these images to create the container. 更好的选择是使用这些图像的dockerfiles来创建容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM