分段错误(核心转储)python [英] Segmentation fault (core dumped) python

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

问题描述

我是python的初学者. 我想从avi文件中读取帧,然后编写以下代码.运行此代码时,我收到诸如Segmentation Fault(Core dumped)之类的消息. 谁能告诉我原因. 我确定我已经使用了avi文件的正确根目录. 我尝试通过ipython查找问题.我发现到达ret的行frame = cap.read()时发生了错误.

I am a beginner to python. I want to read frame from avi files and I write following code.When I run this code I get the message like Segmentation fault (core dumped). Could anyone tell me the reason. I am sure I have used the right root of the avi file. I try to find the problem by ipython. I found the error occured when reach the line of ret, frame = cap.read().

import numpy as np
import cv2

cap = cv2.VideoCapture('/home/sunjia/code/night_goto.avi')

while(cap.isOpened()):
    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()

推荐答案

条件更改"

   while(ret):

尝试一下!

****校正**** 在while循环之前添加以下语句:ret,frame = cap.read() .read()将返回两个参数:frame和boolean:如果读取文件中有任何帧,则为'True',否则为'False'.这样,"ret"将被初始化,并可用于"while()". 现在,while()循环将一直运行,直到循环中的语句"ret,frame = cap.read()"返回参数为止.

**** Correction **** before while loop add this statement: ret, frame = cap.read() .read() will return two parameters: the frame and boolean: 'True' if there is any frame in the read file or 'False' if there is no frame. This way 'ret' will be initialized and can be used for 'while()'. Now, the while() loop will run till the statement "ret, frame = cap.read()" in the loop returns parameters.

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

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