我用的是github下的opencv4.5.1的源码自己编译的,在win10上用vscode搭建的开发环境,一切正常.
附上cmake配置文件:
#设置cmake版本
cmake_minimum_required(VERSION 3.15)
#项目名字
project(main)
#设置编译版本
set(CMAKE_CXX_STANDARD 14)
#设置头文件路径
set(INC_DIR
D:/Opengl/opencv/include
D:/Opengl/opencv/include/opencv2
D:/Gitee/games101/include/eigen
D:/Gitee/games101/include/utils
)
#设置链接库路径
set(LINK_DIR
D:/Opengl/opencv/x64/mingw/bin
D:/Opengl/opencv/x64/mingw/lib
)
set(LINK_LIB
libopencv_core451
libopencv_highgui451
libopencv_imgproc451
libopencv_imgcodecs451
libopencv_video451
libopencv_ml451
libopencv_highgui451
libopencv_objdetect451
libopencv_flann451
libopencv_imgcodecs451
libopencv_photo451
libopencv_videoio451
)
#设源代码路径
set(SRC_DIR
main.cpp
rasterizer.hpp
rasterizer.cpp
Triangle.hpp
Triangle.cpp
)
#引入头文件
include_directories(${INC_DIR})
#引入库文件
link_directories(${LINK_DIR})
#编译文件
add_executable(${PROJECT_NAME} ${SRC_DIR})
#将第三方库连接在一起
target_link_libraries(${PROJECT_NAME} ${LINK_LIB})