pi-top / pi-top-Python-SDK

pi-top's Python SDK (pitop package)
Apache License 2.0
27 stars 4 forks source link

Having hard time with camera #659

Open vovikdrg opened 3 weeks ago

vovikdrg commented 3 weeks ago

My Kids are doing line following but they are constantly getting an error

Exception in thread Thread-7:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/pitop/camera/camera.py", line 294, in __process_camera_output
    self._frame_handler.frame = self._camera.get_frame()
  File "/usr/lib/python3/dist-packages/pitop/camera/core/cameras/usb_camera.py", line 75, in get_frame
    raise ValueError("Couldn't grab frame from camera")
ValueError: Couldn't grab frame from camera

[ WARN:0] global ../modules/videoio/src/cap_v4l.cpp (880) open VIDEOIO(V4L2): can't find camera device
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (1824) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Cannot identify device '/dev/video-1'.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (914) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (501) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0] global ../modules/videoio/src/cap_v4l.cpp (880) open VIDEOIO(V4L2): can't find camera device
Traceback (most recent call last):
  File "/home/pi/Desktop/Projects/Test/Pitoptest.py", line 25, in <module>
    cam = Camera(format="OpenCV")
  File "/usr/lib/python3/dist-packages/pitop/camera/camera.py", line 58, in __init__
    self._camera = UsbCamera(
  File "/usr/lib/python3/dist-packages/pitop/camera/core/cameras/usb_camera.py", line 57, in __init__
    raise IOError(
OSError: Error opening camera. Make sure it's correctly connected via USB.

They do have a loop where they try to grab cam.get_frame and this error occurs.

Could it be that camera it self is dead ?

jcapona commented 3 weeks ago

hi @vovikdrg !

We've seen this issue happen sometimes; you can try:

If you're comfortable using a terminal, you can ssh into the pi-top and check the journal when you're plugging the camera (running journalctl -f) and check if there's relevant information in there...

vovikdrg commented 3 weeks ago

Thanks for that. Now as they connect camera to expansion plate its kind of okay. But i feel camera quality is bad so ordered new one.

vovikdrg commented 3 weeks ago

Another lesson today, seems to be connecting to expansion plate usb make camera stable, but we stopped using camera, and using OpenCV directly + try catch to release camera. Not sure if real issue can be that somehow sdk does not release camera on exit