Ask Your Question

OpenCV with VSCode

asked 2019-04-23 04:06:54 -0500

Petro gravatar image

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:)

edit retag flag offensive close merge delete


Hi! Have any of you figured how to solve this? I'm facing the same problem.

Eduardo Hitek gravatar imageEduardo Hitek ( 2019-06-18 06:38:20 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-05-25 00:44:21 -0500

Hello, have you solved your problem? I met the same problem also, when I ctrl+click the header file, I can navigate to the source code. But when I want to compile and run the code, it give me the error that "no such file or directory".

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-04-23 04:06:54 -0500

Seen: 3,858 times

Last updated: Apr 23 '19