Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 在Mac OSX Sierra上重新打开摄像头并显示时OpenCV崩溃_Macos_Opencv_X11_Webcam - Fatal编程技术网

Macos 在Mac OSX Sierra上重新打开摄像头并显示时OpenCV崩溃

Macos 在Mac OSX Sierra上重新打开摄像头并显示时OpenCV崩溃,macos,opencv,x11,webcam,Macos,Opencv,X11,Webcam,当我在MacOSX Sierra上的OpenCV中重新打开一个网络摄像头并显示其中的图像时,我收到了NSException 这是我用来找出错误模式的测试代码 import cv2 cam = cv2.VideoCapture(0) ret, im = cam.read() cv2.imshow('im', im) cv2.waitKey(1) cam.open(0) ret, im = cam.read() cv2.imshow('im', im) cv2.waitKey(1) cam.o

当我在MacOSX Sierra上的OpenCV中重新打开一个网络摄像头并显示其中的图像时,我收到了NSException

这是我用来找出错误模式的测试代码

import cv2

cam = cv2.VideoCapture(0)
ret, im = cam.read()
cv2.imshow('im', im)
cv2.waitKey(1)

cam.open(0)
ret, im = cam.read()
cv2.imshow('im', im)
cv2.waitKey(1)

cam.open(0)
ret, im = cam.read()
cv2.imshow('im', im)
cv2.waitKey(1)

cam.open(0)
ret, im = cam.read()
cv2.imshow('im', im)
cv2.waitKey(1)
我得到的错误是

2016-11-05 18:15:07.075 Python[1082:24157] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7fca4ac3a6f0 of class AVCaptureDALDevice was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x7fca4ac42f80> (
<NSKeyValueObservance 0x7fca4ae6df50: Observer: 0x7fca4ae6b410, Key path: open, Options: <New: NO, Old: NO, Prior: NO> Context: 0x7fffc9c99570, Property: 0x7fca4ac3fe30>
)'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fffafde96fb __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffc45f0a2a objc_exception_throw + 48
    2   CoreFoundation                      0x00007fffafe669a5 +[NSException raise:format:] + 197
    3   Foundation                          0x00007fffb17d1d84 NSKVODeallocate + 293
    4   AVFoundation                        0x00007fffac67dabe -[AVCaptureDeviceInput _setDevice:exceptionReason:] + 304
    5   AVFoundation                        0x00007fffac5ae914 -[AVCaptureDeviceInput dealloc] + 39
    6   CoreFoundation                      0x00007fffafe53a7b -[__NSSingleObjectArrayI dealloc] + 43
    7   libobjc.A.dylib                     0x00007fffc45e5e60 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 808
    8   CoreFoundation                      0x00007fffafd20d66 _CFAutoreleasePoolPop + 22
    9   CoreFoundation                      0x00007fffafd612c5 __CFRunLoopRun + 2229
    10  CoreFoundation                      0x00007fffafd607b4 CFRunLoopRunSpecific + 420
    11  HIToolbox                           0x00007fffaf2fcfbc RunCurrentEventLoopInMode + 240
    12  HIToolbox                           0x00007fffaf2fcdf1 ReceiveNextEventCommon + 432
    13  HIToolbox                           0x00007fffaf2fcc26 _BlockUntilNextEventMatchingListInModeWithFilter + 71
    14  AppKit                              0x00007fffad9e6b79 _DPSNextEvent + 1093
    15  AppKit                              0x00007fffae0fc1c3 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1637
    16  libopencv_highgui.2.4.dylib         0x000000010d79c0a6 cvWaitKey + 402
    17  cv2.so                              0x000000010cfa3ce1 _ZL16pyopencv_waitKeyP7_objectS0_S0_ + 103
    18  Python                              0x000000010cc001ab PyEval_EvalFrameEx + 27003
    19  Python                              0x000000010cbf963a PyEval_EvalCodeEx + 1617
    20  Python                              0x000000010cbf8fe3 PyEval_EvalCode + 48
    21  Python                              0x000000010cc1cc04 run_mod + 53
    22  Python                              0x000000010cc1cca7 PyRun_FileExFlags + 133
    23  Python                              0x000000010cc1c7f8 PyRun_SimpleFileExFlags + 702
    24  Python                              0x000000010cc2deba Py_Main + 3094
    25  libdyld.dylib                       0x00007fffc4ecd255 start + 1
    26  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

cap\u avfoundation\u mac.mm
中,函数
CvCaptureCAM::stopCaptureDevice
, 评论这行:

[mCaptureDevice release];

cap\u avfoundation\u mac.mm
中,函数
CvCaptureCAM::stopCaptureDevice
, 评论这行:

[mCaptureDevice release];

我不使用/了解Python,但它看起来像是您多次调用
cam.open
而不关闭。是吗?是的,我也用
cam.open(0)
自己检查和释放了。我也尝试过使用插入的
cam.release()
调用。(我更新了我的问题以澄清)我仍然不明白你为什么调用
cam.open
-你似乎在第一帧中不需要它。@MarkSetchell这个代码是我尝试做的玩具版本。我希望我可以使用openCV在ipython笔记本中打开我的相机,但这样做迫使我在一直打开相机连接,还是在运行手机之间关闭相机连接之间做出选择。
cam.release()
后跟
cam.open(0)
表示此过程。显然,在这个测试代码中,这是不必要的,但它会产生我试图调试的错误模式。我不使用/了解Python,但它看起来像是您多次调用
cam.open
而不关闭。是吗?是的,我也用
cam.open(0)
自己检查和释放了。我也尝试过使用插入的
cam.release()
调用。(我更新了我的问题以澄清)我仍然不明白你为什么调用
cam.open
-你似乎在第一帧中不需要它。@MarkSetchell这个代码是我尝试做的玩具版本。我希望我可以使用openCV在ipython笔记本中打开我的相机,但这样做迫使我在一直打开相机连接,还是在运行手机之间关闭相机连接之间做出选择。
cam.release()
后跟
cam.open(0)
表示此过程。显然,在这个测试代码中,这是不必要的,但它会产生我试图调试的错误模式。