OpenCv 代码抛出分段错误(核心转储)Ubuntu 14.04 [英] OpenCv code throws segmentation error(core dumped) Ubuntu 14.04

查看:91
本文介绍了OpenCv 代码抛出分段错误(核心转储)Ubuntu 14.04的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从官方文档学习 opencv 的初学者 http://docs.opencv.org/trunk/doc/py_tutorials/py_gui/py_video_display/py_video_display.html#display-video

I'm beginner learning opencv from the official documentation http://docs.opencv.org/trunk/doc/py_tutorials/py_gui/py_video_display/py_video_display.html#display-video

import numpy as np        
import cv2    

cap = cv2.VideoCapture(0)      
while(True):    
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

它给了我错误 Segmentation fault (core dumped)"谁能告诉我为什么会发生这种情况以及如何解决该问题?
提前致谢.

It's giving me error "Segmentation fault (core dumped)" Can anyone please tell me Why is that happening and how to resolve that issue?
Thanks in advance.

推荐答案

也许有点晚了,但是user3154952"说的是真的,当你使用 C++ api 时,你不需要使用 release 方法,它已经在视频捕获析构函数中.

Maybe its a little late but what "user3154952" says is true, when you are working with the C++ api you don't need to use the release method, it is already in the video capture Destructor.

这是我测试并运行良好的代码:

This is the code i tested and worked fine:

import sys
import cv2

cap = cv2.VideoCapture(0)

while(1):
    ret,frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == 27:
        break

cv2.destroyAllWindows()

更新:我一直在摆弄我的 ps3 眼睛,我意识到使用那台相机会因为仅使用 destroyAllWindows 方法而出现分段错误,为了解决这个问题,我用 release 方法替换了 destroyAllWindows 方法并且工作正常,我没有确切知道为什么会发生这种情况我只是分享以防万一有人遇到这个问题.我希望这会有所帮助.

Update: i have been messing around with my ps3 eye and i've realized that with that camera you get the segmentation error for using only the destroyAllWindows method, to fix that i replaced the destroyAllWindows method with the release method and worked fine, i don't know exactly why that happened i'm just sharing in case someone get that issue. I hope that was helpful.

这篇关于OpenCv 代码抛出分段错误(核心转储)Ubuntu 14.04的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆