资源简介
基于Opencv的简单数字识别,适用于初学者入门,有助于开拓初学者的思维,帮助其更好地入门,代码详细,有很多注释,简单易懂!
代码片段和文件信息
#include
#include
#include
#include
using namespace std;
using namespace cv;
//创建记录轮廓数量和坐标的结构体
struct num_contours
{
double x y; //轮廓的x、y坐标
int index; //轮廓的顺序
bool operator <(num_contours &m)
{
if (y > m.y+50) return false;
else if (y > m.y-50)
{
if (x < m.x) return true;
else return false;
}
else return true;
}
}num_contours[100];
//创建记录结果的结构体
struct result
{
double data;
int num;
bool operator<(result &m)
{
if (data < m.data)return true;
else return false;
}
}result[100];
void select_result(Mat & src int num);
double compare(Mat &src Mat &model);
vector imread_model();
void deal(Mat &src Mat &model int m);
void select_result(Mat & src int num);
int main()
{
Mat src gray_src dest dst;
src = imread(“C:/Users/86159/Desktop/num_text/num_text_02.png“); //加载原图
cvtColor(src gray_src COLOR_BGR2GRAY); //对图像进行预处理
threshold(gray_src dest 150 255 THRESH_BINARY_INV);
vector> contours;
vector hierarchy;
findContours(dest contours hierarchy RETR_EXTERNAL CHAIN_APPROX_NONE Point(0 0)); //提取轮廓
vector rect;
Rect min_bounding_rectre_rect;
float tl_x br_y width height;
for (int i = 0; i < contours.size(); i++)
{
if (contourArea(contours[i]) > 50)
{
min_bounding_rect = boundingRect(contours[i]);
rect.push_back(boundingRect(contours[i]));
tl_x = (float)min_bounding_rect.tl().x;
br_y = (float)min_bounding_rect.br().y;
width = (float)min_bounding_rect.width;
height = (float)min_bounding_rect.height;
num_contours[i].x = (tl_x * 2 + width) / 2.0; //计算轮廓中心点
num_contours[i].y = (br_y * 2 + height) / 2.0;
num_contours[i].index = i;
}
}
sort(num_contours num_contours + contours.size()); //根据轮廓中心点坐标进行排序
vector roi_rect(cont
相关资源
- C++获取计算机的CPU ID,硬盘序列号等
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 人脸识别(opencv_facedetect_v4l2)
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
评论
共有 条评论