[英]OpenCV3 error: “Unable to stop the stream: Inappropriate ioctl for device”
I'm trying to read the frames of an .mov file using OpenCV 3.2 (from the menpo conda channel ). 我正在尝试使用OpenCV 3.2(从menpo conda渠道 )读取.mov文件的框架。 I'm using Python 3.5.3 through Anaconda on an Ubuntu 16.04 64-bit setup.
我正在Ubuntu 16.04 64位设置上通过Anaconda使用Python 3.5.3。
Problem is, I get the following error message from OpenCV when it hits the cap.read()
call, and the loop immediately breaks and catches the if num == 0
conditional. 问题是,当OpenCV命中
cap.read()
调用时,我收到以下错误消息,并且循环立即中断并捕获if num == 0
条件。
Here's the entirety of the code I'm running: 这是我正在运行的全部代码:
import cv2
import numpy as np
import sys
f = sys.argv[1]
cap = cv2.VideoCapture(f)
frames = []
num = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret: break
gframe = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frames.append(gframe)
num += 1
if num % 100 == 0:
frames.append(gframe)
if num % 1000 == 0:
print(num)
if num == 0:
print("Something went wrong: no frames found.")
exit(0)
cap.release()
user@ubuntu:/data$ python read.py movie.mov
Unable to stop the stream: Inappropriate ioctl for device
Something went wrong: no frames found.
user@ubuntu:/data$
I've found a couple of other StackOverflow questions on this topic, but they don't quite translate to my exact circumstance: 我在该主题上还发现了其他一些StackOverflow问题,但它们并不能完全反映我的实际情况:
To that third point--there are quite a few other questions here that have the quote inappropriate ioctl for device
but it's hard to see if any of them is directly relevant to this problem. 到了第三点,这里还有很多其他问题,其中引述了
inappropriate ioctl for device
但很难确定它们是否与该问题直接相关。
As a partial aside: I've installed this exact same opencv3 conda package on my macOS machine, and the code I've pasted here works just fine and on exactly the same .mov file I've tried on the Ubuntu machine. 暂且不说:我已经在macOS机器上安装了这个完全相同的opencv3 conda软件包,并且我粘贴到此处的代码在我在Ubuntu机器上尝试过的完全相同的.mov文件上也可以正常工作。
Any ideas? 有任何想法吗?
Solved the problem by getting around it entirely. 通过完全解决问题来解决该问题。
Used the opencv-feedstock recipe of OpenCV for conda-forge. 使用OpenCV的opencv-feedstock配方进行conda-forge。 In the
recipe
folder is the build information for conda. 在
recipe
文件夹中是conda的构建信息。 I modified the build.sh
file, changing the following options: 我修改了
build.sh
文件,更改了以下选项:
-DBUILD_PNG=1
-DBUILD_JPEG=1
-DWITH_CUDA=1
-DWITH_FFMPEG=1
ran conda build --numpy 1.12 recipe
from the parent directory (had to specify the NumPy version, as the build script requirement lists numpy xx
which means you have to provide the version at runtime), and waited. 从父目录运行
conda build --numpy 1.12 recipe
(必须指定NumPy版本,因为构建脚本要求列出了numpy xx
,这意味着您必须在运行时提供版本),然后等待。
Took forever (seriously, a couple hours on a very powerful machine--the time sink is CUDA), but the build eventually completed successfully. 没完没了 (严重的是,几个小时一个非常强大的机器上-时间接收器是CUDA),但最终构建成功完成。
Then it was just a matter of installing the locally-built bz2 archive ( conda install --use-local opencv
). 然后,只需安装本地构建的bz2归档文件(
conda install --use-local opencv
)。 No more weird ioctl error messages, and the above script worked just fine. 没有更多奇怪的ioctl错误消息,并且上面的脚本可以正常工作。
I faced the same problem with Anaconda private env & Python 3.5 on Ubuntu 16.04 . 我在Ubuntu 16.04上使用Anaconda private env和Python 3.5遇到了同样的问题。
Initially installed Opencv3 using 最初使用Opencv3安装
conda install -c menpo opencv3
Solution: 解:
Remove Opencv3 conda remove opencv3
删除Opencv3 conda
conda remove opencv3
Install Opencv3 using pip install opencv-contrib-python
使用
pip install opencv-contrib-python
安装Opencv3
If the problem still persists: 如果问题仍然存在:
sudo apt-get install ffmpeg
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev
sudo apt-get install ffmpeg
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.