简体   繁体   English

OpenCV3错误:“无法停止流:设备的不适当的ioctl”

[英]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问题,但它们并不能完全反映我的实际情况:

  • This question proposes rebuilding OpenCV (also uses Python 2). 这个问题建议重建OpenCV(也使用Python 2)。 That's not an option for me, as I'm trying to do this with Anaconda. 这不是我的选择,因为我正在尝试使用Anaconda进行此操作。
  • These two questions ( here and here ) on the OpenCV forums were left without any satisfactory answers. OpenCV论坛上的这两个问题( 此处此处 )都没有令人满意的答案。
  • This one has a lively discussion and a thorough answer, but it's specific to perl. 这是一个热烈的讨论,并且有完整的答案,但这是针对perl的。

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: 解:

  1. Remove Opencv3 conda remove opencv3 删除Opencv3 conda conda remove opencv3

  2. Install Opencv3 using pip install opencv-contrib-python 使用pip install opencv-contrib-python安装Opencv3

If the problem still persists: 如果问题仍然存在:

  1. Uninstall OpenCV 卸载OpenCV
  2. Install dependencies 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
  3. Reinstall Opencv using step 2. 使用步骤2重新安装Opencv。

暂无
暂无

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

相关问题 opencv无法阻止流:设备的ioctl不合适 - opencv Unable to stop the stream: Inappropriate ioctl for device 崇高的tset:标准错误:设备的ioctl不适当 - Sublime tset: standard error: Inappropriate ioctl for device Pexpect和PyCharm - 适用于设备的ioctl - Pexpect and PyCharm - Inappropriate ioctl for device 如何抑制“stty:'标准输入':设备的 ioctl 不合适”错误 - How to supress the “stty: 'standard input': Inappropriate ioctl for device” error IOError:[Errno 25] 设备的 ioctl 不合适 - IOError: [Errno 25] Inappropriate ioctl for device 在Python中运行ioctl会返回ENOTTY-设备不适合的ioctl - Running ioctl in Python returns ENOTTY - inappropriate ioctl for device 詹金斯的pipenv shell返回问题termios.error:(25,'不合适的设备ioctl') - pipenv shell in Jenkins return the issue termios.error: (25, 'Inappropriate ioctl for device') X 服务器“localhost:10.0”上的 matplot lib“致命 IO 错误 25(设备的 ioctl 不合适)” - matplot lib "fatal IO error 25 (Inappropriate ioctl for device) on X server "localhost:10.0" 当在具有PowerCLI的VM上运行时,pexpect的interact()报告“不适当的设备ioctl” - pexpect's interact() reported “Inappropriate ioctl for device” when running on a VM with PowerCLI “GetPassWarning:无法控制终端上的回声”是什么意思? “设备的 ioctl 不合适”? - What does "GetPassWarning: Can not control echo on the terminal" mean? "Inappropriate ioctl for device"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM