Ask Your Question

Revision history [back]

OpenCV with VSCode

Thank you always for your help. I am trying to compile an OpenCV project with Visual Studio Code on Ubuntu. The code is like this:

include iostream; include opencv2/core.hpp; include opencv2/highgui.hpp; include opencv2/imgcodecs.hpp; using namespace cv; int main() { Mat mat = cv::imread("image.jpg", cv::IMREAD_COLOR); namedWindow("Test", cv::WINDOW_AUTOSIZE); imshow("Test", mat); WaitKey(0); destroyAllWindows();

return 0; }

I am sorry to write the "include" lines in a wired form. The question form seems to render differently.

The code was successfully compiled by g++ test.cpp -I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui but I cannot see how can I compile on VSCode.

I modified the c_cpp_properties.json file as "includePath":[${workspaceFolder}/**, "/usr/local/include/opencv4", /usr/local/lib] but it complains that fatal error: opencv2/core.hpp: No such file or directory.

I also cannot understand why there have been generated two opencv.hpp files in my environment: /home/user-name/opencv/include/opencv2/opencv.hpp /usr/local/include/opencv4/opencv2/opencv.hpp This duplicate files might cause the problem?

Thank you advance:)