Fwd: Error Releasing VideoCapture in OpenCV Using GStreamer Pipeline

Gaspar Ramôa ramoa.science at gmail.com
Thu Nov 14 12:28:14 CET 2024


Hello Laurent,

Sorry for the double reply, but I was already able to solve the problem 
I sent you in the previous email.

Here's the solution, (I might create another issue on GitHub and close 
it with the solution to help others):

I am still quite not sure, but basically gstreamer does not support the 
same *frame sizes* has the ones from the *sensor format*.

When I do the command: *rpicam-vid --list-cameras: *I get the following 
sensor format: 1640x1232 - 41 FPS
Available cameras
-----------------
0 : imx219 [3280x2464 10-bit RGGB] (/base/soc/i2c0mux/i2c at 1/imx219 at 10)
     Modes: 'SRGGB10_CSI2P' : 640x480 [103.33 fps - (1000, 752)/1280x960 
crop]
*1640x1232* [41.85 fps - (0, 0)/3280x2464 crop]
                              1920x1080 [47.57 fps - (680, 
692)/1920x1080 crop]
                              3280x2464 [21.19 fps - (0, 0)/3280x2464 crop]
            'SRGGB8' : 640x480 [103.33 fps - (1000, 752)/1280x960 crop]
*1640x1232* [41.85 fps - (0, 0)/3280x2464 crop]
                       1920x1080 [47.57 fps - (680, 692)/1920x1080 crop]
                       3280x2464 [21.19 fps - (0, 0)/3280x2464 crop]

In the gstreamer pipeline I was using this format size, and although I 
was getting 41 fps, my frames had this *striping *effect.

  * libcamerasrc camera-name=/base/soc/i2c0mux/i2c at 1/imx219 at 10 !
    video/x-raw,*width=1640,height=1232*,format=RGBx,framerate=41/1 !
    videoconvert ! appsink

After looking up, I installed gstreamer1.0-plugins-base-apps and use the 
command *gst-device-monitor-1.0 Video *to check which gstreamer video 
streaming formats were available for my camera. And I checked that there 
was no 1640x1232 option, but a similar one 1600x1200 (same ratio as 
640x480). I then tried with this frame size format and it is now working 
at 41fps with no striping effect:

  * libcamerasrc camera-name=/base/soc/i2c0mux/i2c at 1/imx219 at 10 !
    video/x-raw,*width=1600,height=1200*,format=RGBx,framerate=41/1 !
    videoconvert ! appsink



I just have another short question. Now that gstreamer works properly 
and I can release the capture without that warning/error. I want to know 
if I can use libcamerasrc without having to activate this environment 
under /libcamera/build/ with *meson devenv -C build. *If I don't do 
this, I cannot use gstreamer with libcamerasrc, the libcamerasrc is not 
recognize for some reason.

Isn't it possible to just install libcamera where *libcamerasrc *is 
available without this virtual environment?


Best Regards,

Gaspar



On 13/11/2024 19:00, Gaspar Ramôa wrote:
>
> Hello Laurent Pinchart,
>
>
> Thank you for the quick reply!
>
> As I created the issue 3 months ago and got no reply from you I 
> thought that you were no longer active or working in this project, and 
> that is why I said it was difficult to get you! But I am glad I was 
> able to reach you! :-)
>
> I spent the entire afternoon following your suggestion.
>
> So I was successfully able to install the latest version of libcamera 
> and the latest version of the rpicam-apps:
>
> /rpicam-apps build: v1.5.3 50958df98d3c 13-11-2024 (16:55:55)
> rpicam-apps capabilites: egl:1 qt:1 drm:1 libav:1
> libcamera build: v0.3.2+98-75fe515a/
>
> However when trying to run *gst-inspect-1.0 libcamerasrc *the system 
> could not find the libcamerasrc. I had to activate some environment 
> under /libcamera/build/ with *meson devenv -C build*
>
> After this I was able to start the capture and release it *without any 
> errors or warnings*. This is really a great positive step for me!
>
> The frame saved is still weird but I think you probably know what is 
> missing here. I know that I still have to use some tunnig-files but 
> the horizontal strips I have no idea what they are. I am using *format 
> *= BGR and x-raw video on the gstreamer pipeline. Do you have any idea 
> on how to convert these to the normal RGB. Like using the 
> *rpicam-still *-o test.png gives me this:
>
> And I able getting something like this from the gstreamer pipeline:
>
> Any ideas? Where can I find the documentation of *libcamerasrc *so I 
> can have an idea on what I can change/do.
>
>
> My end goal is to just be able to use the benefits of libcamera 
> (changing analog gain, exposure, etc) in JAVA.
>
>
> Best Regards,
>
> Gaspar Ramôa
>
>
> On 13/11/2024 14:35, Laurent Pinchart wrote:
>> Hello Gaspar,
>>
>> On Wed, Nov 13, 2024 at 12:51:11PM +0100, Gaspar Ramôa wrote:
>>> Dear libcamera community,
>>>
>>> Thank you for developing such a helpful library.
>> I'm glad you find it helpful.
>>
>>> I am trying to get frames using opencv. I am actually able to get frames via
>>> cv2.VideoCapture through GStreamer.
>>>
>>> However, when I try to release the capture (for ending the program or maybe
>>> adjusting raw image size): cap.release()
>>> I get the following error:
>>>
>>> [1:39:52.854669803] [1885] ERROR DeviceEnumerator device_enumerator.cpp:172
>>> Removing media device /dev/media4 while still in use
>>> [1:39:52.854709759] [1885] ERROR DeviceEnumerator device_enumerator.cpp:172
>>> Removing media device /dev/media3 while still in use
>>>
>>> I've already published an issue on the raspberry Pi libcamera GitHub repo where
>>> you can get more detail on my problem:https://github.com/raspberrypi/libcamera
>>> /issues/163
>>>
>>> I found the following commit which apparently did to solve the problem I am
>>> having now:https://github.com/raspberrypi/libcamera/commit/
>>> fa63d428aef62bacf0a6ad1622a7965b3ff2ba2f
>> That commit has been merged a long time ago, before v0.0.1, so I expect
>> it is included in the libcamera version you are using. Your problem may
>> have the same symptoms but a different root cause.
>>
>> You mentioned in your bug report that you tried both libcamera v0.0.5
>> and v0.3.0+65-6ddd79b5. v0.0.5 is fairly old. v0.3.0 is better, but I
>> would still recommend trying the latest master branch to see if the
>> issue has been fixed already.
>>
>> If the issue is still present, can you try running the same GStreamer
>> pipeline (likely replacing appsink with some sort of display sink, or
>> even fakesink) from gst-launch, and see if the problem exists there too
>> ?
>>
>>> This commit was done by the userhttps://github.com/pinchartl. But I have no
>>> way of contacting him to help me fix the problem.
>> I'm slightly puzzled by why you had trouble contacting me, given that my
>> e-mail address is listed in the commit you mentioned above. Regardless,
>> it looks like you found a way :-)
>>
>>> Any suggestions? Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20241114/735bfad5/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: R4s64YHg0dcuMvBd.png
Type: image/png
Size: 365108 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20241114/735bfad5/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 81zagJetsec9pZAp.png
Type: image/png
Size: 428906 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20241114/735bfad5/attachment-0003.png>


More information about the libcamera-devel mailing list