Gstreamer with Opencv support?

I have been running the basic_pipelines/detection_pipeline.py using own trained yolov8n model successfully.

I wanted to integrate cameraundistort and perspective from opencv, started with undistortion. This is how I adapted the code:

def get_pipeline_string(self):
# Camera calibration parameters
camera_matrix = “700,0,640,0,700,360,0,0,1” # Example values
distortion_coeffs = “-0.3,0.1,0,0,0” # Example values

    # Modify the source pipeline to include undistortion
    source_pipeline = f"""
        {SOURCE_PIPELINE(self.video_source)} ! 
        videoconvert ! 
        cameraundistort camera-matrix=\"{camera_matrix}\" distortion-coefficients=\"{distortion_coeffs}\"
    """
    
    detection_pipeline = INFERENCE_PIPELINE(
        hef_path=self.hef_path,
        post_process_so=self.post_process_so,
        batch_size=self.batch_size,
        config_json=self.labels_json,
        additional_params=self.thresholds_str)
    user_callback_pipeline = USER_CALLBACK_PIPELINE()
    display_pipeline = DISPLAY_PIPELINE(video_sink=self.video_sink, sync=self.sync, show_fps=self.show_fps)
    pipeline_string = (
        f'{source_pipeline} '
        f'{detection_pipeline} ! '
        f'{user_callback_pipeline} ! '
        f'{display_pipeline}'
    )
    print(pipeline_string)
    return pipeline_string

I get following error message:
gst_parse_error: no element “cameraundistort” (1)

        filesrc location="/home/pi/hailo-testJoFe/output.mp4" name=source ! queue name=source_queue_dec264 leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0  ! qtdemux ! h264parse ! avdec_h264 max-threads=2 !  queue name=source_scale_q leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0  ! videoscale name=source_videoscale n-threads=2 ! queue name=source_convert_q leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0  ! videoconvert n-threads=3 name=source_convert qos=false ! video/x-raw, format=RGB, pixel-aspect-ratio=1/1 !  
        videoconvert ! 
        cameraundistort camera-matrix="700,0,640,0,700,360,0,0,1" distortion-coefficients="-0.3,0.1,0,0,0"
     queue name=inference_scale_q leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0  

I found out:
gst-inspect-1.0 --plugin opencv
No such element or plugin ‘opencv’

I tried to compile opencv, gtreamer, … but without success.

My question(s):
Is opencv supported within Gstreamer?
If yes, how to get it working?

Thanks for your support :slight_smile:

Hi @johnfee welcome to our community.
Gstreamer does not come with opencv support as default. You may need to install it manually or compile from source.
See Gstreamer documentation for support.

Thank you for the fast reply.

Which versions of Gstreamer and opencv do I need to compile?
… I think here is my problem.

I am using the latest hailo SW software from January 2025 on Raspi.