我对raspberry pi和python都很新。我已经编写了一个分析图像的代码,但我不断发生致命的python错误:( pygame parachute)Segmentation Fault。它通常发生在我的程序中15分钟到一个小时之间。从我所读到的,这通常是某种内存超越问题。我还没有找到能够解决我问题的具体答案。这是我的代码。请帮忙。有没有人对如何修复或调试这个问题有任何建议?
var utcPickedDate = $scope.pickedDate.toUTCString(); //"Thu, 09 Feb 2017 21:33:16 GMT"
我不知道其中的大部分内容,但是如果我在(gdb)中运行程序并进行回溯,我会得到这个......
import cv2
from SimpleCV import Image, Camera
import time
import os
import RPi.GPIO as GPIO
T = 1
z = 0
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(31, GPIO.OUT)
GPIO.setup(32, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.output(31,GPIO.HIGH)
cam = Camera(prop_set={'width':320, 'height':240})
while(T):
w = [0 in range(9)]
if(GPIO.input(32)):
start = 80
pixel = 0
end = 225
time.sleep(0.32)
img = cam.getImage()
img.save('original.jpg')
edges = cv2.imread('original.jpg')
edges = cv2.Canny(edges,90,210)
print("hola")
for y in range (100,160):
i = 0
first = 0
temp = 0
last = 0
for x in range (start, end):
pixel = edges[y,x]
if (pixel >=120 and first == 0):
first = x
if (pixel >=120 and first != 0 and last < x):
last = x
if last != 0:
temp = last - first
for x in range(start, end):
if ((x <= last) and (x >=first)):
edges[y,x] = 140;
while(GPIO.input(32)):
pass
今天我发现,如果我所做的只是导入SimpleCV,图像和相机,然后打开相机并进入无限循环,我仍然会出现分段错误
(gdb) bt
#0 0x000835f4 in PyEval_EvalFrameEx ()
#1 0x00081ca4 in PyEval_EvalCodeEx ()
#2 0x000c37c4 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
如果我使用pygame拍摄照片并进行回溯,我会收到更多信息的分段错误
(gdb) bt
#0 0x00087024 in PyEval_EvalFrameEx ()
#1 0x000840cc in PyEval_EvalFrameEx ()
#2 0x000a4520 in ?? ()
我找到了gdb的新功能。我输入信息主题,我得到......
#0 0x0006de50 in PyErr_Format ()
#1 0x70952ee0 in v412_read_frame () from /usr/lib/python2.7/dist-packages/pygame/_camera.so
#2 0x7094ede0 in camera_get_image () from /usr/lib/python2.7/dist-packages/pygame/_camera.so
#3 0x0008360c in PyEval_EvalFrameEx ()
#4 0x00081ca4 in PyEval_EvalCodeEx ()
#5 0x000c37c4 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
然后,如果我输入列表,我会得到这个
Id Target ID Frame
2 Thread 0x72df9460 (LWP 601) "python2.7" 0x76e3ab80 in poll ()at ../sysdeps/unix/syscall-template.S:81
*1 Thread 0x76ff6000 (LWP 600) "python2.7" 0x0006de50 in PyErr_Format ()
我相信星号意味着这是结束程序的线程,但我不确定。有谁知道从这里做什么?
答案 0 :(得分:0)
这在技术上不是一个答案,而是更多的解决方法。我完全放弃了SimpleCV。我不知道SimpleCV,pygame中是否有错误,或者它是否只是我的头脑。我发现如果我使用pygame来拍照并每分钟重新初始化它,我就不会遇到分段错误。
import cv2
import numpy as np
import pygame
import pygame.camera
import time
import os
import RPi.GPIO as GPIO
T = 1
z = 0
buff = 0
flag = 0
pygame.camera.init()
pygame.camera.list_cameras()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(31, GPIO.OUT)
GPIO.setup(32, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.output(31,GPIO.HIGH)
while(T):
w = [0 in range(9)]
if (flag == 0):
print("Ready")
flag = 1
if (z == 0):
z+=1
camera = pygame.camera.Camera("/dev/video0",(320,240))
camera.start()
if(GPIO.input(32) and (z>=1)):
start = 80
pixel = 0
end = 225
time.sleep(0.32)
for buff in range(0,5):
img = camera.get_image()
pygame.image.save(img, "original.jpg")
edges = cv2.imread("pic.jpg")
edges = cv2.Canny(edges,90,210)
np.edges = edges
for y in range (100,160):
i = 0
first = 0
temp = 0
last = 0
for x in range (start, end):
pixel = np.edges[y,x]
if (pixel >=120 and first == 0):
first = x
if (pixel >=120 and first != 0 and last < x):
last = x
if last != 0:
temp = last - first
for x in range(start, end):
if ((x <= last) and (x >=first)):
edges[y,x] = 140;
z=0;
camera.stop()
while(GPIO.input(32)):
pass
使用此代码,只要您每分钟至少拍摄一张照片,它就不会分段。我曾经一次测试了大约25个小时,另一个测试了12个小时。如果您不需要经常拍照,可以在下次需要时停止相机并重新初始化。我希望这会对某人有所帮助,因为这对我来说是个问题,持续数周。