I'm learning OpenCV and I'm using c++. I installed opencv in my ubuntu using the libopencv-dev and python3-opencv packegs in ubuntu 20.04 from this tutorial: https://linuxize.com/post/how-to-install-opencv-on-ubuntu-20-04/ but when I try to run a sample program using this command g++ -I/usr/local/include/opencv4 Example1.cpp -o Example1
I get this error:
Example1.cpp: In function ‘int main(int, char**)’:
Example1.cpp:5:2: error: ‘IplImage’ was not declared in this scope
5 | IplImage* img = cvLoadImage( argv[1] );
| ^~~~~~~~
Example1.cpp:5:12: error: ‘img’ was not declared in this scope
5 | IplImage* img = cvLoadImage( argv[1] );
| ^~~
Example1.cpp:5:18: error: ‘cvLoadImage’ was not declared in this scope
5 | IplImage* img = cvLoadImage( argv[1] );
| ^~~~~~~~~~~
Example1.cpp:6:29: error: ‘CV_WINDOW_AUTOSIZED’ was not declared in this scope
6 | cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZED );
| ^~~~~~~~~~~~~~~~~~~
Example1.cpp:6:2: error: ‘cvNamedWindow’ was not declared in this scope
6 | cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZED );
| ^~~~~~~~~~~~~
Example1.cpp:7:2: error: ‘cvShowImage’ was not declared in this scope
7 | cvShowImage( "Example1", img );
| ^~~~~~~~~~~
Example1.cpp:8:2: error: ‘cvWaitKey’ was not declared in this scope
8 | cvWaitKey(0);
| ^~~~~~~~~
Example1.cpp:9:2: error: ‘cvReleaseImage’ was not declared in this scope
9 | cvReleaseImage( &img );
| ^~~~~~~~~~~~~~
Example1.cpp:10:2: error: ‘cvDestroyWindow’ was not declared in this scope
10 | cvDestroyWindow( "Example1" );
| ^~~~~~~~~~~~~~~
here is the source code:
#include <opencv2/highgui.h>
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZED );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
}
and the pkg-config output(if it's needed):
p4n0@p4n0-desktop:~/Desktop/Example_Project$ pkg-config --cflags opencv
-I/usr/local/include/opencv4
p4n0@p4n0-desktop:~/Desktop/Example_Project$ pkg-config --libs opencv
-L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
To use IplImage , you need to include opencv2/core/types_c.h
Edit:- Since you are using OpenCV4, those includes are not available for you. They were removed.
In C++, like other languages to use a function you need to import it so the compiler can find the function during it's compilation step
Off topic suggestion:- This applies in case you are not forced to use IplImage etc.
If you are allowed to use Modern OpenCV, and are not restricted by old versions, prefer the Modern solutions not the C API.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.