如何解决Pycharm-运行打开的CV代码直接转到“以退出代码139完成的过程被信号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是内存访问冲突,使用来自c ++库的代码时,我发现很多此错误。本质上,您正在尝试访问内存中已删除的对象,但仍然保留对该对象的引用。
致电时
`# after the loop realse the cap object
vid.release()
# destroy all windows
cv2.destroyAllWindows()`
Opencv本质上必须在删除内存中的对象。
然后,当您执行while循环的下一次迭代时,尝试使用此循环访问它们。
`ret,frame = vid.read()
# display the resulting frame
cv2.imshow('frame',frame)`
但是视频捕获对象和窗口不存在(但仍然保留了对python对象的引用)。
然后繁荣,崩溃。因为它找不到对象,也不知道该怎么办。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。