Hello, I am reading the book: "OpenCV " - 2nd edition - By Adrian Kaehler & Gary Bradski.
Right at the very first code example in the book, “First Program - Display a Picture”, I get an error: Segmentation fault (core dumped)
.
Here is the code example from the book:
Example 2-2: A simple OpenCV program that loads an image from disk and displays it on the screen
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main( int argc, char** argv )
{
Mat img = imread( argv[1], -1 );
if( img.empty() ) return -1;
namedWindow( "Example2", WINDOW_AUTOSIZE );
imshow( "Example2", img );
waitKey( 0 );
destroyWindow( "Example2" );
}
I used clang to compile the code using:
clang++ -g opencv_1.cpp -o opencv_1 $(pkg-config --cflags --libs opencv4) -I /usr/local/include/opencv4
I did not get any errors during and after compilation.
When I run the compiled code using:
./opencv_1
I get the following error:
Segmentation fault (core dumped)
Now I have no clue whats causing this error.
Here are the details about my PC:
- OS: FreeBSD 13.1-RELEASE-p1 amd64
- Shell: sh
- Resolution: 3840x2160
- DE: Plasma 5.24.6
- WM: KWin
- Theme: [Plasma], Breeze [GTK2/3]
- Icons: [Plasma], breeze-dark [GTK2/3]
- Terminal: konsole
- CPU: AMD FX-8350 (8) @ 3.991GHz
- GPU: Ellesmere [Radeon RX 580]
- Memory: 5755MiB / 32684MiB
I have compiled OpenCV 4.5.5_9 from source using:
cd /usr/ports/graphics/opencv/ && make reinstall clean
I have also tried running the OpenCV compiled C++ code using the pkg
installation of OpenCV 4.5.5_9 rather than using the compilation of FreeBSD ports source:
pkg install graphics/opencv
Doesn’t matter if is use either the pkg
or ports version of OpenCV, I get the same error.
Here are some details about the OpenCV which is currently installed.
(Note: this is the compilation version from FreeBSD Ports on graphics/OpenCV):
pkg info opencv
opencv-4.5.5_9
Name : opencv
Version : 4.5.5_9
Installed on : Fri Aug 26 22:54:00 2022 EDT
Origin : graphics/opencv
Architecture : FreeBSD:13:amd64
Prefix : /usr/local
Categories : graphics
Licenses : BSD3CLAUSE
Maintainer : desktop@FreeBSD.org
WWW : https://www.opencv.org/
Comment : Open Source Computer Vision library
Options :
ATLAS : off
DC1394 : on
EIGEN : on
FFMPEG : off
GDAL : on
GDCM : on
GPHOTO2 : on
GSTREAMER : on
GTK3 : off
HARDENING : off
JASPER : off
JAVA : off
JPEG : on
LTO : off
NOBLAS : off
OPENBLAS : on
OPENCL : on
OPENEXR : on
OPENJPEG : on
PATENTED : off
PNG : on
PROTOBUF : on
PYTHON : on
TBB : off
TESSERACT : off
TIFF : on
V4L : on
VTK : off
VULKAN : on
WEBP : on
XINE : off
Shared Libs required:
libwebp.so.7
libtiff.so.5
libpng16.so.16
libopenjp2.so.7
libopenblas.so.0
libjpeg.so.8
libhdf5.so.200
libharfbuzz.so.0
libgstvideo-1.0.so.0
libgstriff-1.0.so.0
libgstreamer-1.0.so.0
libgstpbutils-1.0.so.0
libgstbase-1.0.so.0
libgstaudio-1.0.so.0
libgstapp-1.0.so.0
libgphoto2_port.so.12
libgphoto2.so.6
libgobject-2.0.so.0
libglog.so.1
libglib-2.0.so.0
libgdcmMSFF.so.3.0
libgdcmDSED.so.3.0
libgdal.so.3
libfreetype.so.6
libdc1394.so.25
libOpenEXR-3_1.so.30
Shared Libs provided:
libopencv_xphoto.so.405
libopencv_xobjdetect.so.405
libopencv_ximgproc.so.405
libopencv_xfeatures2d.so.405
libopencv_wechat_qrcode.so.405
libopencv_videostab.so.405
libopencv_videoio.so.405
libopencv_video.so.405
libopencv_tracking.so.405
libopencv_text.so.405
libopencv_surface_matching.so.405
libopencv_superres.so.405
libopencv_structured_light.so.405
libopencv_stitching.so.405
libopencv_stereo.so.405
libopencv_shape.so.405
libopencv_sfm.so.405
libopencv_saliency.so.405
libopencv_rgbd.so.405
libopencv_reg.so.405
libopencv_rapid.so.405
libopencv_quality.so.405
libopencv_plot.so.405
libopencv_photo.so.405
libopencv_phase_unwrapping.so.405
libopencv_optflow.so.405
libopencv_objdetect.so.405
libopencv_ml.so.405
libopencv_mcc.so.405
libopencv_line_descriptor.so.405
libopencv_intensity_transform.so.405
libopencv_imgproc.so.405
libopencv_imgcodecs.so.405
libopencv_img_hash.so.405
libopencv_highgui.so.405
libopencv_hfs.so.405
libopencv_hdf.so.405
libopencv_gapi.so.405
libopencv_fuzzy.so.405
libopencv_freetype.so.405
libopencv_flann.so.405
libopencv_features2d.so.405
libopencv_face.so.405
libopencv_dpm.so.405
libopencv_dnn_superres.so.405
libopencv_dnn_objdetect.so.405
libopencv_dnn.so.405
libopencv_datasets.so.405
libopencv_core.so.405
libopencv_ccalib.so.405
libopencv_calib3d.so.405
libopencv_bioinspired.so.405
libopencv_bgsegm.so.405
libopencv_barcode.so.405
libopencv_aruco.so.405
libopencv_alphamat.so.405
Annotations :
FreeBSD_version: 1301000
cpe : cpe:2.3:a:opencv:opencv:4.5.5:::::freebsd13:x64:9
Flat size : 96.8MiB
Anyone have any clue whats causing this error for such basic code?
Thanks for any advice.