I am fairly new to both the raspberry pi and python. I have written a code to analyze an image, but I keep getting fatal python error: (pygame parachute) Segmentation Fault. It usually occurs between 15 minutes and an hour into my program. From what I have read, this is typically some sort of memory overreach problem. I haven't found any concrete answers that have been able to solve my problem. Here is my code. My memory usage never goes above 33% when I launch the program in the GUI. I also occasionally get a Fatal Python error: ceval: tstate mix-up. Please help. Any information on how to fix or debug this problem would be greatly appreciated.
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
I don't know what most of it means, but if I run the program in (gdb) and do a backtrace, I get this......
(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?)
Today I found that if all that I do is import SimpleCV, image and camera, then open a camera and enter an infinite loop, I still get a segmentation fault
(gdb) bt
#0 0x00087024 in PyEval_EvalFrameEx ()
#1 0x000840cc in PyEval_EvalFrameEx ()
#2 0x000a4520 in ?? ()
If I take the photo using pygame and do a backtrace, I get a segmentation fault with slightly more information
#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?)
I found a new function of gdb. I type info threads and I get...
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 ()
then if I type list I get this
1 ../sysdeps/unix/syscall-template.S: No such file or directory
I believe that the asterisk means that is the thread that ended the program, but I am not certain. Does anybody know what to do from here? Or have any ideas of how to fix this or work around it??