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