Rosrun cv_camera_node failed with GStreamer

I just add an camera ros package to handle csi camera with below commands

sudo apt-get install ros-noetic-cv-camera

When I launch the package it failed, any one knows how to fix this issue?

$ rosrun cv_camera cv_camera_node
[ WARN:0] global ../modules/videoio/src/cap.cpp (163) open VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...

(cv_camera_node:14209): GStreamer-CRITICAL **: 12:58:10.268:
Trying to dispose element pipeline0, but it is in PAUSED instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline

(cv_camera_node:14209): GStreamer-CRITICAL **: 12:58:10.269:
Trying to dispose element videoconvert0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

(cv_camera_node:14209): GStreamer-CRITICAL **: 12:58:10.269:
Trying to dispose element appsink0, but it is in READY instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

[ WARN:0] global ../modules/videoio/src/cap.cpp (183) open VIDEOIO(GSTREAMER): can't create capture
[ WARN:0] global ../modules/videoio/src/cap.cpp (163) open VIDEOIO(V4L2): trying capture cameraNum=0 ...

(cv_camera_node:14209): GStreamer-CRITICAL **: 12:58:10.280: gst_element_post_message: assertion 'GST_IS_ELEMENT (element)' failed
[ WARN:0] global ../modules/videoio/src/cap.cpp (174) open VIDEOIO(V4L2): created, isOpened=1

Hi,
Please try the command and see if you can launch the camera successfully:

$ gst-launch-1.0 nvarguscamerasrc ! nvvidconv ! video/x-raw,format=I420 ! xvimagesink sync=0

If above command works, you can then try the sample:
OpenCV Video Capture with GStreamer doesn't work on ROS-melodic - #3 by DaneLLL

It works with above command “$ gst-launch-1.0 nvarguscamerasrc ! nvvidconv ! video/x-raw,format=I420 ! xvimagesink sync=0”

But it doesn’t work in OpenCV Video Capture with GStreamer doesn't work on ROS-melodic - #3 by DaneLLL

$ gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1’ ! nvoverlaysink

And I think hardware is OK. Is it something to do with ros-noetic-cv-camera? Right now I don’t know what to do with this. I’m new to ROS.

Hi,
In the sample width,height,framerate is set to 1920x1080p30. Probably your camera source does not support this mode. Please check which modes your camera support and configure width,height,framerate to fit the mode.

IMX219 csi camera, which comes with the dev kit. I think it should support.

Hi,
Please run the command to ensure gstreamer is enabled in OpenCV:

nvidia@tegra-ubuntu:~$ python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.getBuildInformation())

General configuration for OpenCV 4.8.0 =====================================
  Version control:               4.8.0-1-g6371ee1

  Platform:
    Timestamp:                   2023-08-29T05:11:38Z
    Host:                        Linux 5.15.111-tegra aarch64
    CMake:                       3.22.1
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/gmake
    Configuration:               Release

  CPU/HW features:
    Baseline:                    NEON FP16

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /usr/bin/c++  (ver 11.4.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virt
ual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declara
tions -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized
-Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthro
ugh=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-point
er -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlin
es-hidden -fstack-protector-strong -fPIC -O3 -DNDEBUG  -DNDEBUG -D_FORTIFY_SOURC
E=2
    C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virt
ual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declara
tions -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized
-Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthro
ugh=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-point
er -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlin
es-hidden -fstack-protector-strong -fPIC -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress
-Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-pro
totypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wunini
tialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostic
s-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections
   -fvisibility=hidden -fstack-protector-strong -fPIC -O3 -DNDEBUG  -DNDEBUG -D_
FORTIFY_SOURCE=2
    C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress
-Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-pro
totypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wunini
tialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostic
s-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections
   -fvisibility=hidden -fstack-protector-strong -fPIC -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed -Wl,--no-unde
fined  -z noexecstack -z relro -z now
    Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed -Wl,--no-unde
fined  -z noexecstack -z relro -z now
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m pthread rt
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann gapi highgui
imgcodecs imgproc ml objdetect photo python3 stitching ts video videoio
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 java python2
    Applications:                tests perf_tests examples apps
    Documentation:               NO
    Non-free algorithms:         NO

  GUI:                           GTK2
    GTK+:                        YES (ver 2.24.33)
      GThread :                  YES (ver 2.72.4)
      GtkGlExt:                  NO

  Media I/O:
    ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
    JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.3
7)
    TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 /
 4.3.0)
    JPEG 2000:                   build (ver 2.5.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    FFMPEG:                      YES
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                NO
    GStreamer:                   YES (1.20.3)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2021.5 interface 12050)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       YES (ver 3.4.0)
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.19.1)
    Flatbuffers:                 builtin/3rdparty (23.5.9)

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.18)
    Libraries:                   NO
    numpy:                       NO (Python wrappers can not be generated)
    install path:                -

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.10.12)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.10.so (ver 3.10.12)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.21.5)
    install path:                lib/python3.10/dist-packages/cv2/python-3.10

  Python (for build):            /usr/bin/python2.7

  Java:
    ant:                         NO
    Java:                        NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /usr/local
-----------------------------------------------------------------


>>>

If gstreamer is enabled, please try the gstreamer pipeline in cv2.VideoCapture():

cap = cv2.VideoCapture("videotestsrc is-live=1 ! video/x-raw,format=BGR,width=1920,height=1080 !  appsink")

See if it works with videotestsrc plugin.

  1. gstreamer is enabled
  2. plugin seems NOT OK

So, what I have missed here?

daniel@nvidia:~$ python3
Python 3.8.10 (default, Nov 22 2023, 10:22:35)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.getBuildInformation())

General configuration for OpenCV 4.2.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /build/opencv-EQP6mK/opencv-4.2.0+dfsg/contrib/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2020-02-18T03:31:25Z
    Host:                        Linux 4.4.0-173-generic aarch64
    CMake:                       3.16.3
    CMake generator:             Ninja
    CMake build tool:            /usr/bin/ninja
    Configuration:               Release

  CPU/HW features:
    Baseline:                    NEON FP16
      required:                  NEON
      disabled:                  VFPV3

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/bin/c++  (ver 9.2.1)
    C++ flags (Release):         -g -O2 -fdebug-prefix-map=/build/opencv-EQP6mK/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g -O2 -fdebug-prefix-map=/build/opencv-EQP6mK/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG
    C++ flags (Debug):           -g -O2 -fdebug-prefix-map=/build/opencv-EQP6mK/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -g -O2 -fdebug-prefix-map=/build/opencv-EQP6mK/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g -O2 -fdebug-prefix-map=/build/opencv-EQP6mK/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG
    C flags (Debug):             -g -O2 -fdebug-prefix-map=/build/opencv-EQP6mK/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now  -Wl,--gc-sections -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now
    Linker flags (Debug):        -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now  -Wl,--gc-sections
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m pthread rt
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy hdf hfs highgui img_hash imgcodecs imgproc java line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab viz ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      sfm
    Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv gapi js matlab ovis python2 ts
    Applications:                apps
    Documentation:               doxygen python javadoc
    Non-free algorithms:         NO

  GUI:
    GTK+:                        YES (ver 3.24.13)
      GThread :                  YES (ver 2.63.3)
      GtkGlExt:                  NO
    OpenGL support:              NO
    VTK support:                 YES (ver 6.3.0)

  Media I/O:
    ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
    JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
    WEBP:                        /usr/lib/aarch64-linux-gnu/libwebp.so (ver encoder: 0x020e)
    PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.37)
    TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.1.0)
    OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath.so /usr/lib/aarch64-linux-gnu/libIlmImf.so /usr/lib/aarch64-linux-gnu/libIex.so /usr/lib/aarch64-linux-gnu/libHalf.so /usr/lib/aarch64-linux-gnu/libIlmThread.so (ver 2.3.0)
    GDAL:                        YES (/usr/lib/libgdal.so)
    GDCM:                        YES (3.0.4)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.5)
    FFMPEG:                      YES
      avcodec:                   YES (58.54.100)
      avformat:                  YES (58.29.100)
      avutil:                    YES (56.31.100)
      swscale:                   YES (5.5.100)
      avresample:                YES (4.0.0)
    GStreamer:                   YES (1.16.2)
    PvAPI:                       NO
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2020.1 interface 11101)

  Trace:                         YES (built-in)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       YES (ver 3.3.7)
    Custom HAL:                  NO
    Protobuf:                    /usr/lib/aarch64-linux-gnu/libprotobuf.so (3.6.1)

  OpenCL:                        YES (no extra features)
    Include path:                /usr/include/CL
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.8.2)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.8.so (ver 3.8.2rc1)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.17.4)
    install path:                lib/python3.8/dist-packages

  Python (for build):            /usr/bin/python3

  Java:
    ant:                         /usr/bin/ant (ver 1.10.7)
    JNI:                         /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    /usr
-----------------------------------------------------------------


>>> cap = cv2.VideoCapture("videotestsrc is-live=1 ! video/x-raw,format=BGR,width=1920,height=1080 !  appsink")
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=1, duration=-1

Hi,
Running only cv2.VideoCapture() may not work. Please run a full python sample.

Yeah, it now works.

But I still can’t get image from rosrun rqt_image_view rqt_image_view

daniel@nvidia:~/Test$ python3 test.py
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3280 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3280 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1640 x 1232 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
   Camera index = 0
   Camera mode  = 2
   Output Stream W = 1920 H = 1080
   seconds to Run    = 0
   Frame Rate = 29.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
^CTraceback (most recent call last):
  File "test.py", line 19, in <module>
    read_cam()
  File "test.py", line 11, in read_cam
    cv2.waitKey(10)
KeyboardInterrupt
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success

daniel@nvidia:~/Test$ cat test.py
import sys
import cv2

def read_cam():
    cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert !  appsink")
    if cap.isOpened():
        cv2.namedWindow("demo", cv2.WINDOW_AUTOSIZE)
        while True:
            ret_val, img = cap.read();
            cv2.imshow('demo',img)
            cv2.waitKey(10)
    else:
     print("camera open failed")

    cv2.destroyAllWindows()


if __name__ == '__main__':
    read_cam()

Hi,
You may need to check source code of the application. The gstreamer pipeline in cv2.VideoCapture() may be different and needs to be updated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.