无法关闭/开启CameraCapture使用Python / opencv:设备或资源繁忙 [英] Cannot turn off/on CameraCapture using Python/opencv: Device or resource busy
问题描述
当我尝试使用Python重新打开opencv的CameraCapture时,我得到:
libv4l2:错误设置pixformat:设备或资源繁忙
HIGHGUI错误:libv4l无法ioctl S_FMT
libv4l2:错误设置pixformat:设备或资源繁忙
libv4l1:错误设置pixformat:设备或资源繁忙
HIGHGUI错误:libv4l无法ioctl VIDIOCSPICT
虽然我的应用程序使用PyQt和其他模块,我能够孤立的问题。所以当我点击r(重新加载)捕获对象被删除,但我不能重新打开一个连接到相机,因为它仍然活动:
#!/ usr / bin / env python
从opencv.cv import *
从opencv.highgui import *
import sys
import time
import gc
cvNamedWindow(w1,CV_WINDOW_AUTOSIZE)
camera_index = 1
capture = cvCreateCameraCapture(camera_index)
def repeat():
全局捕获#declare为全局变量,因为我们现在分配给它们
全局camera_index
frame = cvQueryFrame(capture)
cvShowImage w1,frame)
c = cvWaitKey(10)
如果c ==q:
sys.exit(0)
c ==r:
print'reload'
#del frame
del capture
#相当无用的睡眠,垃圾收集等。
#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?和/或 OpenCV / Array应该是CvMat或IplImage /释放捕获对象
问题是你不是使用OpenCV API释放捕获组件。
你不应该使用 del捕获
。正确的方法是通过:
cvReleaseCapture(capture)
pre>
When I try to re-open opencv's CameraCapture using Python I get:
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
Although my application runs in a bigger context using PyQt and various other modules, I was able to isolate the problem. So when I hit "r" (reload) the capture object is deleted but I'm not able to re-open a connection to the camera since it is still active:
#!/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()
The hints given for similar questions did not work for me: cant find ReleaseCapture in opencv while using python? and/or OpenCV / Array should be CvMat or IplImage / Releasing a capture object
解决方案The problem is that you are not releasing the capture component using the OpenCV API.
You shouldn't do
del capture
. The right way to do it is through:cvReleaseCapture(capture)
这篇关于无法关闭/开启CameraCapture使用Python / opencv:设备或资源繁忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!