Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program crashes with PiCameraRuntimeError "Timed out waiting for capture to end" #1

Open
DarthVi opened this issue Oct 15, 2019 · 7 comments

Comments

@DarthVi
Copy link

DarthVi commented Oct 15, 2019

Hi,
I've tinkered a little bit with your code in order to make it run fullscreen and I placed an instruction in /etc/xdg/lxsession/LXDE-pi/autostart to make it autostart when the LXDE starts. The rest of the code is pretty much the same original one.

However sometimes when I boot up the raspberry the code crashes and by redirecting stderr on a log file I found out this traceback:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1704, in capture_continuous
    'Timed out waiting for capture to end')
picamera.exc.PiCameraRuntimeError: Timed out waiting for capture to end

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/mlx90640-library/thermal.py", line 45, in <module>
    for frame in camera.capture_continuous(rawCapture, format="rgb", use_video_port=True):
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1710, in capture_continuous
    encoder.close()
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 431, in close
    self.stop()
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 419, in stop
    self._close_output()
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 349, in _close_output
    mo.close_stream(output, opened)
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 371, in close_stream
    stream.flush()
  File "/usr/lib/python3/dist-packages/picamera/array.py", line 238, in flush
    self.array = bytes_to_rgb(self.getvalue(), self.size or self.camera.resolution)
  File "/usr/lib/python3/dist-packages/picamera/array.py", line 127, in bytes_to_rgb
    'Incorrect buffer length for resolution %dx%d' % (width, height))
picamera.exc.PiCameraValueError: Incorrect buffer length for resolution 288x368

I'm not expert on the picamera and the odd thing is that other times it works perfectly. If there was an error for the buffer length for resolution, shouldn't the code always fail instantly?
Is there a way to fix this issue?

@leswright1977
Copy link
Owner

Weird. Looks like it tries to pull a frame form the picam, but the picam isnt ready. Try putting a reasonable delay in the script before starting the picam, then another after initialization and before pulling frames. See if that fixes it. I'm no expert on the picam either, but it can be a bit awkward at times, and seems to need time to settle.

@DarthVi
Copy link
Author

DarthVi commented Oct 30, 2019

I tried right now putting time.sleep(0.3) before and after camera = PiCamera() and before for frame in camera.capture_continuous(rawCapture, format="rgb", use_video_port=True):.

There's still the same issue: sometimes it works and continues working, other times it works for a couple of seconds and then crashes with the stacktrace previously shown.

@leswright1977
Copy link
Owner

leswright1977 commented Oct 31, 2019

I think you need a much bigger delay than that. In some instances I have put in delays as long as 10 seconds to ensure stuff has settled down. When you call the script from autostart is there any significant delay in there? I had a similar issue trying to autostart a chromium session in kisok mode, where the executable was being called before other programs it relied on (and networking) had been loaded. You need to give LXDE a chance to settle down first...

@DarthVi
Copy link
Author

DarthVi commented Nov 25, 2019

With a 7 seconds delay, the initial crashes occur less frequently. Since for UX reasons I don't want to have too much delay, I coded a monitor that restarts the application when it crashes (and when it crashes, it happens only once during the firsts seconds, so it does not bother me too much).

I have another question that is slightly off-topic, but I don't think it deserves another issue page, so I'm gonna ask it here:
why is there a if(val > 99.99) val = 99.99; check on line 115 of mlx90640_driver.cpp?
I tried commenting it in order to register higher temperatures, then tested it on the burners on my stove, it does detect higher temperature without me noticing any problem.

@leswright1977
Copy link
Owner

Hi,
cool. 
You asked: why is there a if(val > 99.99) val = 99.99; check on line 115 of mlx90640_driver.cpp?  I did it to normalize the colorization of the display for likely temperatures in a room like setting. I figured it was unlikely for my application to come across anything at over 100 deg for the thing I was using it for.
Feel free to hack it up for your purpose. The MLX90640 is capable of reading up to 300 Degrees Celcius, and down to -40.

@DarthVi
Copy link
Author

DarthVi commented Nov 25, 2019

Ok, thanks!

@ph1lj-6321
Copy link

How did you compile the Mlx90649_driver.cpp - do I need the bcm8235 lib installed ? - I have tried Geany on the Pi and I get errors.
If I test the circuit with i2cdetect -y 1, I get back the i2c address 33 - but all the compiler in Geany say is that the address is unknown
Can anyone offer any help ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants