![](/img/trans.png)
[英]How can I solve “process finished with exit code 139 (interrupted by signal 11: SIGSEGV)” in opencv - cv2 ( Pycharm & macOS)?
[英]Pycharm - Running Open CV Code goes straight to “Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)”
我正在尝试运行 open-cv 代码以在 python 脚本中访问我的网络摄像头。 但是,当我尝试运行它时,每次尝试运行它时都会收到“进程完成,退出代码 139(被信号 11:SIGSEGV 中断)”。 我的代码没有错误,我还查看了其他帖子以添加环境变量: PYTHONUNBUFFERED=1;PYDEVD_USE_FRAME_EVAL=NO;PYTHONMALLOC=debug
我的代码是:
import cv2
# define a video capture object
vid = cv2.VideoCapture(0)
while (True):
# Capture the video frame
# by frame
ret, frame = vid.read()
# display the resulting frame
cv2.imshow('frame', frame)
# the 'q button is set as the
# quitting button
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# after the loop realse the cap object
vid.release()
# destroy all windows
cv2.destroyAllWindows()
最后两行必须在 while 循环之外:
import cv2
# define a video capture object
vid = cv2.VideoCapture(0)
while (True):
# Capture the video frame
# by frame
ret, frame = vid.read()
# display the resulting frame
cv2.imshow('frame', frame)
# the 'q button is set as the
# quitting button
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# after the loop realse the cap object
vid.release()
# destroy all windows
cv2.destroyAllWindows()
添加到此。
SIGSEGV 是 memory 访问冲突,我在使用来自 c++ 库的代码时经常发现此错误。 本质上,您正在尝试访问 memory 中的 object 已被删除但对它的引用仍然存在。
当你调用这些
`# after the loop realse the cap object
vid.release()
# destroy all windows
cv2.destroyAllWindows()`
Opencv 本质上必须删除 memory 中的 object。
然后,当您执行 while 循环的下一次迭代时,您会尝试使用它来访问它们。
`ret, frame = vid.read()
# display the resulting frame
cv2.imshow('frame', frame)`
但是视频捕获 object 和 window 不存在(但对 python ZA8CFDE6331BD59EB2AC966F8911C4B 的引用仍然存在)。
然后繁荣,崩溃。 因为找不到 object 不知道怎么办。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.