OpenCV 4.5.1
C++20
Ubuntu 20.04
素材
来源,基于 K近邻博文 中原5000个手写数字得到的按行排列的手写数字数据以及对应行的标签, 保存为图片后直接放到这里使用,避免重复数据处理
(右键图片另存为)
行数据.png
标签.png
3.png
组态档
# 设置用于构建该项目的最低cmake版本
cmake_minimum_required(VERSION 3.1)
# 设置项目名称和编程语言
project(opencv_demo CXX)
# 寻找opencv的头文件和库文件
find_package(OpenCV REQUIRED)
# opencv头文件路径
include_directories(${OpenCV_INCLUDE_DIRS})
# opencv库路径
link_directories(${OpenCV_LIBRARY_DIRS})
# 自定义头文件路径
include_directories(include)
# 设置二进制文件生成路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# 获取源码的路径
aux_source_directory(src src)
# 设置编译标准和额外参数
add_compile_options(-std=c++20 -Wall -Werror -Wextra -pedantic -Wimplicit-fallthrough -Wsequence-point -Wswitch-default -Wswitch-unreachable -Wswitch-enum -Wstringop-truncation -Wbool-compare -Wtautological-compare -Wfloat-equal -Wshadow=global -Wpointer-arith -Wpointer-compare -Wcast-align -Wcast-qual -Wwrite-strings -Wdangling-else -Wlogical-op -Wconversion -Wno-pedantic-ms-format)
# 从源码构建二进制文件
add_executable(demo ${src})
# 链接opencv库到二进制文件
target_link_libraries(demo ${OpenCV_LIBRARIES})
源码
/**
* @file dtrees.cpp
* @author IYATT-yx 2514374431@qq.com
* @date 2021-3-14
* @brief 基于决策树的手写数字识别 (OpenCV 4.5.1)
*/
#include <iostream>
#include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
#include "opencv2/ml.hpp"
#include "opencv2/imgproc.hpp"
int main()
{