解决:打开opencv安装文件夹下的OpenCVConfig.cmake文件(我的文件路径是D:\opencv\opencv\build\OpenCVConfig.cmake)修改倒数第二行 将 set(OpenCV_FOUND FALSE) 改为 set(OpenCV_FOUND TRUE)
解决,CMakeLists.txt中加上
include_directories(D:\\opencv\\opencv\\build\\include\\)
include_directories(D:\\opencv\\opencv\\build\\include\\opencv2)
我的完整的CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(path_smoother)add_compile_options(-std=c++11)set(OpenCV_DIR D:\\opencv\\opencv\\build\\)
find_package(OpenCV 4.5.1 REQUIRED COMPONENTS core highgui imgproc)
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(D:\\opencv\\opencv\\build\\include\\)
include_directories(D:\\opencv\\opencv\\build\\include\\opencv2)add_library(${PROJECT_NAME}bucket_queue.hmath_utils.hpose2d.hvec2d.hvec2i.hconstants.hpath_smoother.hbucket_queue.cppvec2d.cpppath_smoother.cpp)target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})add_executable(path_smoother_example path_smoother_example.cpp)
target_link_libraries(path_smoother_example ${PROJECT_NAME} ${OpenCV_LIBS})
解决:save workspace as… 创建一个.code-workspace文件,添加一行"cmake.generator": “Unix Makefiles”
{"folders": [{"path": "."}],"settings": {"cmake.generator": "Unix Makefiles"}
}
解决办法:头文件不在vscode默认文件夹下,因此还得再配置vscode的搜索头文件位置才能得到代码提示
ctrl shift p 选择C/C++ edit configuration
修改c_cpp_properties.json,在include path 中增加搜索文件(opencv的头文件路径)
我的文件:
{"configurations": [{"name": "Win32","includePath": ["${workspaceFolder}/**","D:/opencv/opencv/build/include/**","D:/opencv/opencv/build/include/opencv2/**"],"defines": ["_DEBUG","UNICODE","_UNICODE"],"compilerPath": "D:\\mingw\\mingw64\\bin\\gcc.exe","cStandard": "c17","cppStandard": "gnu++14","intelliSenseMode": "windows-gcc-x64","configurationProvider": "ms-vscode.cpptools"}],"version": 4
}
把c_cpp_properties.json中的 “configurationProvider”,改为ms-vscode.cpptools
这是opencv2的用法,现在opencv3和4是COLOR_GARY2BGR,若还报错,则应该是cv::COLOR_GARY2BGR(加上命名空间)