当我尝试使用 Python 重新打开 opencv Camera Capture 时,我得到:
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()
针对类似问题给出的提示对我不起作用:使用python时无法在opencv中找到ReleaseCapture? https://stackoverflow.com/questions/6691546/cant-find-releasecapture-in-opencv-while-using-python and/or OpenCV / Array 应该是 CvMat 或 IplImage / 释放捕获对象 https://stackoverflow.com/questions/5140230/opencv-array-should-be-cvmat-or-iplimage-releasing-a-capture-object
问题是您没有使用 OpenCV API 发布捕获组件。
你不应该这样做del capture
。正确的方法是通过:
cvReleaseCapture(capture)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)