I'm using OpenCV 4.7.0 built from source in Ubuntu 20.04 and I'm getting a segmentation fault Segmentation fault (core dumped) while calling a Gaussian Blur or getStructuringElement in c++:
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
// some code to:
// read the image, 
// convert it to grayscale and filter it (median filter)
// type2str: https://stackoverflow.com/a/17820615
std::string ty =  type2str( filtered_img.type() );
printf("Matrix: %s %dx%d \n", ty.c_str(),
 filtered_img.cols, filtered_img.rows );
// https://stackoverflow.com/a/19488679
try
    {   
        std::cout << "Before Gaussian Filter" << std::endl;
        cv::GaussianBlur(filtered_img, filtered_img,
                          cv::Size(3, 3), 0);
    }
    catch( cv::Exception& e )
    {
        const char* err_msg = e.what();
        std::cout << "exception caught: " 
        << err_msg << std::endl;
    }
// same issue with `getStructuringElement`
try
    {
        cv::Mat dil_kernel = cv::getStructuringElement( dilation_type,
                       cv::Size( 2*dial_k + 1, 2*dial_k+1 ),
                       cv::Point( dial_k, dial_k ) );
    }
    catch( cv::Exception& e )
    {
        const char* err_msg = e.what();
        std::cout << "exception caught: " << err_msg << std::endl;
    }
output:
Matrix: 8UC1 371x442 
Before Gaussian Filter
Segmentation fault (core dumped)
I have seen the image cv::imshow('img', filtered_img) before passing it to the Gaussian Filter and it seems to be OK, and I have passed this image to a median filter and worked properly, can you please tell me how can I solve this issue please? thanks in advance.