raspberrypi / picamera2

New libcamera based python library
BSD 2-Clause "Simplified" License
892 stars 188 forks source link

Dequeue timer expires / picamera2 crashes in dark environments #854

Closed matbhe closed 1 year ago

matbhe commented 1 year ago

Bug description It seems that streaming / recording really dark environments causes the following error (after some time): [12:37:57.133376596] [5093] WARN V4L2 v4l2_videodevice.cpp:2007 /dev/video0[15:cap]: Dequeue timer of 1000000.00us has expired! After this error the camera is no longer working and the program must be restarted. I've tried to configure the ExposureTime / FrameDurationLimits but nothing fixed it.

Steps to Reproduce

  1. wget https://raw.githubusercontent.com/raspberrypi/picamera2/main/examples/mjpeg_server.py
  2. Place camera in really dark room (almost no light)
  3. Run python3 mjpeg_server.py
  4. Wait some time (1-5 min) and then the error occurs

Expected behaviour The "dequeue timer expired" - error should not occur even there is no light at all.

Console Output

[12:37:57.133376596] [5093]  WARN V4L2 v4l2_videodevice.cpp:2007 /dev/video0[15:cap]: Dequeue timer of 1000000.00us has expired!
[12:37:57.133547853] [5093] ERROR RPI pipeline_base.cpp:1374 Camera frontend has timed out!
[12:37:57.133612426] [5093] ERROR RPI pipeline_base.cpp:1375 Please check that your camera sensor connector is attached securely.
[12:37:57.133674351] [5093] ERROR RPI pipeline_base.cpp:1376 Alternatively, try another cable and/or sensor.

Hardware / Software

More informations I've tested the behavior multiple times:

davidplowman commented 1 year ago

@naushir Any ideas on this one?

naushir commented 1 year ago

The watchdog timer should get adjusted based on the framerate the sensor is currently running, so it should not trigger in dark environments where the exposure may be longer. It is also a 1s timeout, and our frametime is 100ms, so there's plenty of margin. Let me see if I can reproduce this.

naushir commented 1 year ago

I've been trying to reproduce this without much success. Note I've used a normal ov5647, not a NOIR variant, but I very much doubt that makes a difference.

I wonder if there is actually an electrical problem with the sensor and/or the camera connector cable. A 1s timeout for a 0.1s frame interval is quite a long time, so it does suggest things are going wrong eclectically. I cannot say why this seems to happen in dark conditions and not bright conditions though, that's a bit confusing.

matbhe commented 1 year ago

I have another RaspberryPI4 (not CM4) with the same camera (not the same software). I have now removed the camera from this RaspberryPI and connected it to my CM4. Tests are in progress...

matbhe commented 1 year ago

Result: The problem persists even with a different camera (same model) and a different cable.

naushir commented 1 year ago

My board ran all night without failures. This was on a Pi 4, not CM4 though. Did your setup fail with the Pi4 board as well? What kind of environment are you running the camera in? Is there any chance of electrical interference causing this?

matbhe commented 1 year ago

I would say it is a quite normal environment (basement in the house, wifi, nothing special). I cannot test it at the moment on the Pi4 because I have to prepare an SD card first (with the same os/packages). I will test it. However, I have noticed before that the camera pipeline also stalls on the PI4 every few days/weeks (much less than on the CM4). Unfortunately, the problem can then only be solved with a complete reboot. Either there is a problem with this camera type / batch or it is some kind of software problem....

matbhe commented 1 year ago

I think there could be another cause of the problem: The camera has two IR LEDs attached and these LEDs are automatically turned on when it gets dark (photo resistor). Perhaps this is causing a problem with the power supply of the camera. I'll disconnect the LEDs and see what happens...

matbhe commented 1 year ago

I've spent some time and tried to analyze the behavior. The problem seems to be related to the IR LED's:

IR LED's detached The camera is working fine and stable

IR LED's attached to directly camera (as designed) In a really dark environment each IR-LED will provide the max output power of 3w (according to the spec). In this situation the camera crashes after some time (as already describen in the issue). Because of this behavior I've initially tought that the increased current is the culprit (voltage drop etc.). But this seems not the case...

IR LED's attached to 3.3v rail of PI Same situation as above (dark, 100% LED power) but the camera does not crash.

IR LED's attached to camera with extension wires Same situation as above (dark, 100% LED power) but the camera does not crash. My current assumption is now that the heat generated by the LEDs is causing the problems.

What are your toughts?

naushir commented 1 year ago

Ah, ok, to this is likely because of the power limit that can be drawn over the camera connector cable. It would definitely be recommended to use an external power source, not the rails going up the camera corrector.

naushir commented 1 year ago

I'll close this down now as I'm pretty sure we've identified the culprit. Please reopen if you are still experiencing issues.

MSaviorTR commented 1 year ago

Hello everyone! I just encountred same issue too. I was using my Official Raspberry Pi Camera v2.1 (IMX219) on Rasp Pi 4 and it started to not respond. I have tried it with another Rasp Pi 4 and it couldn't solve the problem. I just wonder that is about hardware or something else like shortcircuit etc. I also changed the CSI cable. What could be the issue if it is about hardware? However, I don't think that is about hardware or components. Because, Rasp Pi recognize the sensor but cannot capture anything.

from picamera2 import Picamera2

picam2 = Picamera2()
picam2.start()

For this code, output is below.

[5:55:58.812302496] [2455]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+82-2783c8d8
[5:55:58.847497400] [2456]  WARN RPI vc4.cpp:383 Mismatch between Unicam and CamHelper for embedded data usage!
[5:55:58.848479950] [2456]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media0 and ISP device /dev/media1
[5:55:58.848594838] [2456]  INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
[5:55:58.855309539] [2455]  INFO Camera camera.cpp:1033 configuring streams: (0) 640x480-XBGR8888 (1) 640x480-SBGGR10_CSI2P
[5:55:58.856078313] [2456]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 640x480-SBGGR10_1X10 - Selected unicam format: 640x480-pBAA

However, when I try to capture an image with code that below:

from picamera2 import Picamera2

picam2 = Picamera2()
picam2.start()
picam2.capture_file("img.png")

It responds like that:

[5:59:18.904755857] [2472]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+82-2783c8d8
[5:59:18.937802416] [2473]  WARN RPI vc4.cpp:383 Mismatch between Unicam and CamHelper for embedded data usage!
[5:59:18.938728133] [2473]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media0 and ISP device /dev/media1
[5:59:18.938813632] [2473]  INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
[5:59:18.948974941] [2472]  INFO Camera camera.cpp:1033 configuring streams: (0) 640x480-XBGR8888 (1) 640x480-SBGGR10_CSI2P
[5:59:18.949949917] [2473]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 640x480-SBGGR10_1X10 - Selected unicam format: 640x480-pBAA
[5:59:20.036045749] [2473]  WARN V4L2 v4l2_videodevice.cpp:2007 /dev/video0[15:cap]: Dequeue timer of 1000000.00us has expired!
[5:59:20.036174081] [2473] ERROR RPI pipeline_base.cpp:1333 Camera frontend has timed out!
[5:59:20.036214877] [2473] ERROR RPI pipeline_base.cpp:1334 Please check that your camera sensor connector is attached securely.
[5:59:20.036254173] [2473] ERROR RPI pipeline_base.cpp:1335 Alternatively, try another cable and/or sensor.
^CTraceback (most recent call last):
  File "/home/mehdi/seda_rpi/single_n.py", line 5, in <module>
    picam2.capture_file("img.png")
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1230, in capture_file
    return self.dispatch_functions(functions, wait, signal_function)
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1203, in dispatch_functions
    return job.get_result() if wait else job
  File "/usr/lib/python3/dist-packages/picamera2/job.py", line 77, in get_result
    return self._future.result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 435, in result
    self._condition.wait(timeout)
  File "/usr/lib/python3.9/threading.py", line 312, in wait
    waiter.acquire()
KeyboardInterrupt

I hope you guys can suggest any solutions. Thank you.

davidplowman commented 1 year ago

Is this also a problem that occurs only in dark environments, as per the issue title? Thanks.

MSaviorTR commented 1 year ago

Actually, no, it is not. I used the camera many times with high exposure times in dark boxes but even then it was not failed. So should I create a new "Issue"?

davidplowman commented 1 year ago

Yes please. Please also report:

Thanks!

MSaviorTR commented 1 year ago

Thanks a lot!

oknoote commented 10 months ago

Thanks a lot!

Could you provide a link to the issue created as I'm experiencing exactly the same issues. Thank you!

MSaviorTR commented 9 months ago

Thanks a lot!

Could you provide a link to the issue created as I'm experiencing exactly the same issues. Thank you!

https://github.com/raspberrypi/picamera2/issues/873

oknoote commented 9 months ago

Thanks a lot!

Could you provide a link to the issue created as I'm experiencing exactly the same issues. Thank you!

https://github.com/raspberrypi/picamera2/issues/873

Awesome, thanks.

MSaviorTR commented 9 months ago

Thanks a lot!

Could you provide a link to the issue created as I'm experiencing exactly the same issues. Thank you!

https://github.com/raspberrypi/picamera2/issues/873

Awesome, thanks.

Cant tell me how to fix this problem? The link is not exist now!

I have changed the sensor on the board. Its issue was about the sensor or the tiny ribbon cable of it. I couldn't figure out clearly. Do not implement any procedure on the board that causes any other problems.