Title: Ubuntu22.04 VScode installation and OpenCV C++ configuration
OpenCV C++ environment construction detailed pictures and texts
VScode installation
Download the installation package
-
Ubuntu软件商店安装的会出现无法输入中文,所以我们选择官网的
。 -
Official website: Download Visual Studio Code - Mac, Linux, Windows
Install
-
Enter the installation package directory
-
dpkg -i ./code_1.73.1-1667967334_amd64.deb
Configure VScode C++
plugin store
-
Install Chinese plug-in
-
Install C++ plugin
-
Configure OpenCV
-
Create a new cpp file, import opencv, and enter the configuration interface from the error message.
-
#include <opencv2/opencv.hpp> #include <opencv2/highgui.hpp> #include <iostream> using namespace std; using namespace cv; Mat src; int main(int argc, char ** argv) { src = imread("./img/QQ图片20220623232420.jpg");//这里是你的图片 if (src.empty()) { cout << "没有读取到图像" << endl; return -1; } imshow("hello", src); waitKey(0); return 0; }
-
Note: Since I have already configured it, I modified the library name in order to report an error. Please refer to the code block above for the code. The code in the picture is incorrect.
-
Add
/usr/local/include/opencv4
.
-
Running error
Report an error
- Error message: No opencv2 file or directory
-
Reason: As shown in the figure, OpenCV has an extra file opencv4 folder in Ubuntu, but the source code has not been changed.
-
Solution: Modify the tasks.json file and import all libraries during compilation.
-
Add the following code to args in tasks.json.
-
"-I", "/usr/local/include", "-I", "/usr/local/include/opencv4", "-I", "/usr/local/include/opencv4/opencv2", "-L", "/usr/local/lib", "-l", "opencv_aruco", "-l", "opencv_bgsegm", "-l", "opencv_bioinspired", "-l", "opencv_calib3d", "-l", "opencv_ccalib", "-l", "opencv_core", "-l", "opencv_datasets", "-l", "opencv_dnn_objdetect", "-l", "opencv_dnn", "-l", "opencv_dpm", "-l", "opencv_face", "-l", "opencv_features2d", "-l", "opencv_flann", "-l", "opencv_freetype", "-l", "opencv_fuzzy", "-l", "opencv_hfs", "-l", "opencv_highgui", "-l", "opencv_imgcodecs", "-l", "opencv_img_hash", "-l", "opencv_imgproc", "-l", "opencv_line_descriptor", "-l", "opencv_ml", "-l", "opencv_objdetect", "-l", "opencv_optflow", "-l", "opencv_phase_unwrapping", "-l", "opencv_photo", "-l", "opencv_plot", "-l", "opencv_reg", "-l", "opencv_rgbd", "-l", "opencv_saliency", "-l", "opencv_shape", "-l", "opencv_stereo", "-l", "opencv_stitching", "-l", "opencv_structured_light", "-l", "opencv_superres", "-l", "opencv_surface_matching", "-l", "opencv_text", "-l", "opencv_tracking", "-l", "opencv_videoio", "-l", "opencv_video", "-l", "opencv_videostab", "-l", "opencv_ximgproc", "-l", "opencv_xphoto"
-