Ubuntu22.04 VScode installation and OpenCV C++ configuration

Title: Ubuntu22.04 VScode installation and OpenCV C++ configuration

OpenCV C++ environment construction detailed pictures and texts

VScode installation

Download the installation package

Install

  • Enter the installation package directory

  •   dpkg -i ./code_1.73.1-1667967334_amd64.deb
    

Configure VScode C++

plugin store

  • Install Chinese plug-in

    Insert image description here

  • Install C++ plugin

    Insert image description here

  • 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.

      Insert image description here

    • Add /usr/local/include/opencv4.

      Insert image description here

Running error

Report an error

  • Error message: No opencv2 file or directory

Insert image description here

  • Reason: As shown in the figure, OpenCV has an extra file opencv4 folder in Ubuntu, but the source code has not been changed.

    Insert image description here

  • 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"
      

      Insert image description here

Test run through

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_51654869/article/details/128124844