文章目录
- 一.Opencv安装
- 二.Qt搭建opencv开发环境
一.Opencv安装
- 官网下载Opencv安装包
- 双击下载的软件进行解压
3. 系统环境变量添加
二.Qt搭建opencv开发环境
-
创建一个新的Qt项目(Non-Qt Project)
-
打开创建好的项目中的CMakeLists.txt,添加如下代码
# opencv set(OpenCV_DIR "C:\\Program Files\\opencv454\\build") set(OpenCV_INCLUDE_DIRS ${OpenCV_DIR}\\include) set(OpenCV_LIB_DIRS ${OpenCV_DIR}\\x64\\vc15\\lib) set(OpenCV_Debug_LIBS "opencv_world454d.lib") set(OpenCV_Release_LIBS "opencv_world454.lib") include_directories(${OpenCV_INCLUDE_DIRS}) link_directories(${OpenCV_LIB_DIRS}) target_link_libraries(${PROJECT_NAME} PUBLIC ${OpenCV_Debug_LIBS}) target_link_libraries(${PROJECT_NAME} PUBLIC ${OpenCV_Release_LIBS})
-
main.cpp中添加以下代码
#include <iostream> #include <opencv2/opencv.hpp> using namespace std; int main() { cv::Mat img = cv::Mat::zeros(cv::Size(512, 512), CV_8UC3); cv::putText(img, "Hello OpenCV", cv::Point(128, 256), 5, 2, cv::Scalar(0, 0, 255), 3, 8); cv::imshow("img", img); cv::waitKey(0); return 0; }
-
点击运行,显示图像则说明环境搭建成功