python - 无法使用 Python/opencv : Device or resource busy 关闭/打开 CameraCapture

标签 python opencv camera capture v4l2

当我尝试使用 Python 重新打开 opencv 的 CameraCapture 时,我得到:

libv4l2: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl S_FMT

libv4l2: error setting pixformat: Device or resource busy
libv4l1: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT

虽然我的应用程序使用 PyQt 和各种其他模块在更大的上下文中运行,但我能够隔离问题。因此,当我点击“r”(重新加载)时,捕捉对象被删除但我无法重新打开与相机的连接,因为它仍然处于事件状态:

#!/usr/bin/env python

from opencv.cv import *  
from opencv.highgui import *  

import sys
import time
import gc

cvNamedWindow("w1", CV_WINDOW_AUTOSIZE)
camera_index = 1
capture = cvCreateCameraCapture(camera_index)

def repeat():
    global capture #declare as globals since we are assigning to them now
    global camera_index
    frame = cvQueryFrame(capture)
    cvShowImage("w1", frame)
    c = cvWaitKey(10)

    if c == "q":
        sys.exit(0)

    if c == "r":

        print 'reload'

        #del frame
        del capture

        # pretty useless sleeping, garbage collecting, etc.
        #gc.collect()
        #import pdb; pdb.set_trace()
        #print gc.get_objects()
        #print gc.DEBUG_UNCOLLECTABLE
        #time.sleep(2)

        capture = cvCreateCameraCapture(camera_index)

if __name__ == "__main__":
    while True:
        repeat()

针对类似问题给出的提示对我不起作用: cant find ReleaseCapture in opencv while using python?和/或 OpenCV / Array should be CvMat or IplImage / Releasing a capture object

最佳答案

问题是您没有使用 OpenCV API 发布捕获组件。

你不应该做del capture。正确的方法是:

cvReleaseCapture(capture)

关于python - 无法使用 Python/opencv : Device or resource busy 关闭/打开 CameraCapture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9768312/

相关文章:

python - OpenCV Python 错误:错误:函数 cv::binary_op 中的 (-215) (mtype == CV_8U || mtype == CV_8S) && _mask.sameSize(*psrc1)

iphone - iOS : camera orientation

python - Pandas 如何在不丢失列标题的情况下连接两个数据框

Python 子类化和父值赋值

python - 如何获取某个.py文件中定义的所有函数?

c++ - cv::cuda::Stream 选择线程默认流

c# - 附加信息 : OpenCV: Different sizes of objects using c#

ios - 如何调整自定义 iOS 相机应用程序的白平衡设置?

cocoa - 如何使用 AVCaptureFlashMode

python - Django 如何在不同目录下调用同名模板?