LaboratoireMecaniqueLille / crappy

Command and Real-time Acquisition Parallelized in Python
https://crappy.readthedocs.io/en/stable/
GNU General Public License v2.0
78 stars 16 forks source link

CameraGstreamer Bug #116

Closed jeffwitz closed 5 months ago

jeffwitz commented 5 months ago

Hello,

I found two different bugs in CameraGstreamer.

1 ) No pipelines work without the config = True, as it needs to know the size of the image

It would be possible to catch the height and width if they are provide in after videoconvert If it is not given, then you could ask to activate the configuration windows or ask to give those 2 parameters.

2 ) Impossible to have a color image

this code works :

  cam = crappy.blocks.Camera(
      'CameraGstreamer',  # Using the Webcam to acquire the images
      user_pipeline = "v4l2src device=/dev/video0 name=source ! jpegdec ! videoconvert ! video/x-raw,format=BGR",
      nb_channels = 1,
      img_depth = 8,
      config=True,  # Before the test starts, displays a configuration window
      # for configuring the camera
      display_images=True,  # During the test, the acquired images are
      # displayed in a dedicated window
      displayer_framerate=30,  # The maximum framerate for displaying the
      # images
      save_images=False,  # Here, we don't want the images to be recorded
      freq=40,  # Lowering the default frequency because it's just a demo
      debug=False,
      # Sticking to default for the other arguments
      )

but if we pass from : nb_channels = 1 to nb_channels = 3, no color permutation works, It works when using Gstreamer with V4L2 implementation gstreamer_camera_v4l2.py, so I think it could be possible to correct.

WeisLeDocto commented 5 months ago

1)

No pipelines work without the config = True

I just tested the following code on my own webcam, which worked just fine :

cam = crappy.blocks.Camera(
      'CameraGstreamer',
      user_pipeline="gst-launch-1.0 v4l2src device=/dev/video0 name=source ! jpegdec ! videoconvert ! video/x-raw,format=BGR,width=640,height=480,framerate=30/1 ! autovideosink",
      nb_channels=3,
      img_depth=8,
      config=False,
      display_images=True,
      displayer_framerate=30,
      save_images=False,
      freq=40,
      img_shape=(480, 640, 3),
      img_dtype='uint8',
  )

I just need to make sure that the dimension in the pipeline and the one in img_shape match. Please double-check that you're providing the img_shape and img_dtype arguments, and that they're consistent with the pipeline. If still not working, please copy-paste in your response the traceback you get with the debug=True argument set.

2)

but if we pass from : nb_channels = 1 to nb_channels = 3, no color permutation works

Cannot reproduce on my setup, where it's actually the opposite: nb_channels=1 gives me a buggy image, and nb_channels=3 gives me a nice color image. Which makes sense since the format=BGR argument specifies a 3-channels image acquisition.

However, I see that in your pipeline you're omitting the final ! autovideosink or equivalent at the end. As stated in the documentation (maybe not highlighted enough), The pipeline should be given as it would be in a terminal. Internally in Crappy, the last part of the pipeline is discarded and replaced with 'appsink name=sink'. In your case, this means "video/x-raw,format=BGR" is actually ignored ! See my code snippet above for an example of how the pipeline should be provided.

jeffwitz commented 5 months ago

Ok, that workscimg_shape and img_dtype are just needed for config=False.