[C++]vscode中 opencv导入和配置
Reference with full tutorial: https://blog.csdn.net/you_zai/article/details/119848662
QuickStart :
vscode : https://code.visualstudio.com/download
minGW : https://sourceforge.net/projects/mingw-w64/files/
opencv built version for windows : https://pan.baidu.com/s/1Npb0NQbQnjUmWq_VSGJz8g code : TXSB
Step:
1. You don't have to build opencv source code. just follow the link above, and you will get a bulit one.
2. ensure you add all the environment path , openccv ,minggw.
3. install C/C++ extension in VScode , just following another blog in my homepage.
4. There are 2 methods to compile files
a . the following is json file sample
b. use cmake
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Dev\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"C:\\Dev\\opencv\\include",
"-L",
"C:\\Dev\\opencv\\x64\\mingw\\lib",
"-l", "libopencv_calib3d430",
"-l", "libopencv_core430",
"-l", "libopencv_dnn430",
"-l", "libopencv_features2d430",
"-l", "libopencv_flann430",
"-l", "libopencv_gapi430",
"-l", "libopencv_highgui430",
"-l", "libopencv_imgcodecs430",
"-l", "libopencv_imgproc430",
"-l", "libopencv_ml430",
"-l", "libopencv_objdetect430",
"-l", "libopencv_photo430",
"-l", "libopencv_stitching430",
"-l", "libopencv_video430",
"-l", "libopencv_videoio430",
],
"options": {
"cwd": "C:\\Dev\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\Dev\\opencv\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Dev\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
CMakeLists.txt
1. choose gcc compile and ensure you have installed the cmake extension. it is more easy to use.
2. after compiling , you can find Build folder in your project , and your execution file is there
cmake_minimum_required(VERSION 3.15)
project(ImageTreatment3)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:\\Dev\\opencv")
set(CMAKE_BUILD_TYPE "Debug")
find_package(OpenCV 4 REQUIRED)
include_directories(${INC_DIR})
link_directories(${LINK_DIR})
aux_source_directory(${PROJECT_SOURCE_DIR} SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
#OpenCV Lib, 如果添加target_link 后cmake 报警错误CMP0111
target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS})

浙公网安备 33010602011771号