CUDA Accelerated GStreamer Camera Undistort - Examples - Other pipelines

From RidgeRun Developer Wiki
Revision as of 18:40, 28 August 2024 by IFocus (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)




Previous: Examples Index Next: Performance






This page showcases basic usage examples of the cudaundistort element, most of these pipelines can be automatically generated by this tool.

The CAMERA_MATRIX and DISTORTION_PARAMETERS are specific for each camera and lens, they can vary from devices even when using the same configuration from the same manufacturer, for more information on how to set these values, consult the Camera Calibration wiki.

Undistortion on camera input

For Undistortion on Jetpack 5+, NVMM support is a work in progress, so the pipelines need to have caps before the Undistort element that are of type "video/x-raw".

For Jetpack 4.n

export CAPS="video/x-raw(memory:NVMM)"

For Jetpack 5.n

export CAPS="video/x-raw"

Saving Undistort output to MP4


CAMERA_MATRIX="{\"fx\":9.5211633874478218e+02, \"fy\":9.4946222068253201e+02, \"cx\":6.8041416457132573e+02, \"cy\":3.1446117133659988e+02}"
DISTORTION_PARAMETERS="{\"k1\":2.1107496349546324e+01, \"k2\":-2.4383787227376064e+02, \"p1\":-2.4875466379420917e-03, \"p2\":2.2798038164244493e-03, \"k3\":5.9419414118252871e+02, \"k4\":2.1085235633925034e+01, \"k5\":-2.4360553937983042e+02, \"k6\":5.9359831515760391e+02}"

OUTVIDEO=/tmp/undistort_result.mp4

gst-launch-1.0 nvarguscamerasrc \
  ! nvvidconv ! $CAPS \
  ! cudaundistort distortion-model=brown-conrady camera-matrix="$CAMERA_MATRIX" distortion-parameters="$DISTORTION_PARAMETERS" \
  ! nvvidconv ! nvv4l2h264enc bitrate=20000000 ! h264parse ! mp4mux ! filesink location=$OUTVIDEO

Displaying the Undistort output

CAMERA_MATRIX="{\"fx\":9.5211633874478218e+02, \"fy\":9.4946222068253201e+02, \"cx\":6.8041416457132573e+02, \"cy\":3.1446117133659988e+02}"
DISTORTION_PARAMETERS="{\"k1\":2.1107496349546324e+01, \"k2\":-2.4383787227376064e+02, \"p1\":-2.4875466379420917e-03, \"p2\":2.2798038164244493e-03, \"k3\":5.9419414118252871e+02, \"k4\":2.1085235633925034e+01, \"k5\":-2.4360553937983042e+02, \"k6\":5.9359831515760391e+02}"

gst-launch-1.0 nvarguscamerasrc \
  ! nvvidconv ! $CAPS \
  ! cudaundistort distortion-model=brown-conrady camera-matrix="$CAMERA_MATRIX" distortion-parameters="$DISTORTION_PARAMETERS" \
  ! nvvidconv ! nvoverlaysink

Dumping output to fakesink

CAMERA_MATRIX="{\"fx\":9.5211633874478218e+02, \"fy\":9.4946222068253201e+02, \"cx\":6.8041416457132573e+02, \"cy\":3.1446117133659988e+02}"
DISTORTION_PARAMETERS="{\"k1\":2.1107496349546324e+01, \"k2\":-2.4383787227376064e+02, \"p1\":-2.4875466379420917e-03, \"p2\":2.2798038164244493e-03, \"k3\":5.9419414118252871e+02, \"k4\":2.1085235633925034e+01, \"k5\":-2.4360553937983042e+02, \"k6\":5.9359831515760391e+02}"

gst-launch-1.0 nvarguscamerasrc \
  ! nvvidconv ! $CAPS \
  ! cudaundistort distortion-model=brown-conrady camera-matrix="$CAMERA_MATRIX" distortion-parameters="$DISTORTION_PARAMETERS" \
  ! nvvidconv ! fakesink

Streaming via UDP+RTP

Set the HOST variable to the Receiver's IP

CAMERA_MATRIX="{\"fx\":9.5211633874478218e+02, \"fy\":9.4946222068253201e+02, \"cx\":6.8041416457132573e+02, \"cy\":3.1446117133659988e+02}"
DISTORTION_PARAMETERS="{\"k1\":3.8939572818197948e-01, \"k2\":-5.5685725182648649e-01, \"k3\":2.3785352925072494e+00, \"k4\":-1.2037220289124213e+00}"

HOST=127.0.0.1
PORT=12345

# Sender
gst-launch-1.0 nvarguscamerasrc \
  ! nvvidconv ! $CAPS \
  ! cudaundistort distortion-model=fisheye camera-matrix="$CAMERA_MATRIX" distortion-parameters="$DISTORTION_PARAMETERS" \
  ! nvvidconv ! nvv4l2h264enc ! rtph264pay config-interval=10  ! queue ! udpsink host=$HOST port=$PORT
# Receiver
gst-launch-1.0 udpsrc port=$PORT ! 'application/x-rtp, media=(string)video, encoding-name=(string)H264' !  queue ! rtph264depay ! avdec_h264 ! videoconvert ! xvimagesink


Previous: Examples Index Next: Performance