資源簡介
對圖像數字的簡單識別,希望能夠給你們參考參考,主要是將數字的特征匹配,在一定的范圍內視為相識,再確定數字是否是1 2 3 4.。。。。。。。。。。。
代碼片段和文件信息
#include?
#include?
#include????????
#include?
using?namespace?cv;
using?namespace?std;
struct?con
{
????double?xy;?????????????????????//輪廓位置
????int?order;??????????????????????//輪廓向量contours中的第幾個
????bool?operator<(con?&m)
{
????????if(y?>?m.y)?return?false;????
????????else??if(?y?==?m.y)
{
????????????if(x?????????????else?return?false;
????????}???????????????????????????
????????else?return?true;
????}
}con[15];
struct?result
{
????double?bi;
????int?num;
????bool?operator<(result?&m)
{
????????if(bi?????????else?return?false;
????}
}result[15];
Mat?num[15];
Mat?sample;
void?deal(Mat?&srcint?order);
double?compare(Mat?&src?Mat?&sample);
void?Threshold(Mat?&srcMat?&sampleint?m);
int?main(?)
{
????Mat?srcImage?=?imread(“originalSize.png“);
if(!srcImage.data)
{
cout?<“讀取圖片出錯?。 ?< return?false;
}
imshow(“【原圖】“srcImage);
????Mat?dstImage?grayImage?Image;?
????srcImage.copyTo(dstImage);
????cvtColor(srcImage?grayImage?COLOR_BGR2GRAY);???????????????//將原圖像轉化成灰度圖
// imshow(“【灰度圖】“grayImage);??????????????????????????????//顯示灰度圖
????threshold(grayImage?Image?48?255?CV_THRESH_BINARY_INV);??//二值化
imshow(“【二值化圖】“grayImage);????????????????????????????//二值圖
????//定義輪廓和層次結構
????vector>?contours;???//檢測并勾畫輪廓
????vector?hierarchy;?
????findContours(Imagecontours?hierarchy?CV_RETR_EXTERNAL?CV_CHAIN_APPROX_NONE);???//指定findContours()函數僅搜索最外層的輪廓,而不關注內部可能出現的任何輪廓。
Mat?lunkuo?=?Mat::zeros(srcImage.rowssrcImage.colsCV_8UC3);???//創建一個與原圖相同的三通道輪廓圖
for(int?i?=?0;i?>=?0;i?=?hierarchy[i][0])????//依次畫出檢測到的輪廓
{
drawContours(lunkuocontoursiScalar(00255)CV_FILLED8hierarchy);
}
imshow(“【輪廓檢測圖】“lunkuo);?????????????//輪廓圖
????int?i?=?0;
????Point2f?pp[5][4];
????vector>::iterator?It;
????Rect?rect[10];
????for(It?=?contours.begin();It? {????????????????????????//畫出可包圍數字的最小矩形
????????Point2f?vertex[4];??
????????rect[i]?=?boundingRect(*It);???//計算一個輪廓的矩形邊界
????????vertex[0]?=?rect[i].tl();???????????????????????????????????????????????????????????//矩陣左上角的點
????????vertex[1].x?=?(float)rect[i].tl().x?vertex[1].y?=?(float)rect[i].br().y;???????????//矩陣左下方的點
????????vertex[2]?=?rect[i].br();???????????????????????????????????????????????????????????//矩陣右下角的點
????????vertex[3].x?=?(float)rect[i].br().x?vertex[3].y?=?(float)rect[i].tl().y;???????????//矩陣右上方的點
????????for(?int?j?=?0;?j?4;?j++)
????????????line(dstImagevertex[j]?vertex[?(j+1)%4?]Scalar(00255)1);???????//畫出矩形輪廓區域
????????con[i].x?=?(vertex[0].x+vertex[1].x+vertex[2].x+vertex[3].x)?/?4.0;??????????????????//根據中心點判斷圖像的位置
????????con[i].y?=?(vertex[0].y+vertex[1].y+vertex[2].y+vertex[3].y)?/?4.0;
//cout?<????????con[i].order
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-05-26?15:36??數字匹配\
?????目錄???????????0??2018-05-25?21:37??數字匹配\1_HelloOpenCV\
?????文件????35344384??2018-05-26?15:36??數字匹配\1_HelloOpenCV.sdf
?????文件?????????906??2014-11-24?10:35??數字匹配\1_HelloOpenCV.sln
?????文件???????25088??2018-05-26?15:36??數字匹配\1_HelloOpenCV.suo
?????文件????????1633??2017-12-04?19:17??數字匹配\1_HelloOpenCV\0.png
?????文件??????272244??2014-07-24?17:19??數字匹配\1_HelloOpenCV\1.jpg
?????文件?????????666??2017-12-04?19:18??數字匹配\1_HelloOpenCV\1.png
?????文件????????7402??2017-12-27?18:50??數字匹配\1_HelloOpenCV\1_HelloOpenCV.cpp
?????文件????????3982??2017-02-24?20:22??數字匹配\1_HelloOpenCV\1_HelloOpenCV.vcxproj
?????文件?????????951??2014-11-26?09:37??數字匹配\1_HelloOpenCV\1_HelloOpenCV.vcxproj.filters
?????文件?????????143??2014-11-24?10:35??數字匹配\1_HelloOpenCV\1_HelloOpenCV.vcxproj.user
?????文件????????1576??2017-12-04?19:19??數字匹配\1_HelloOpenCV\2.png
?????文件???????65291??2017-03-01?21:24??數字匹配\1_HelloOpenCV\3.jpg
?????文件????????1746??2017-12-04?19:20??數字匹配\1_HelloOpenCV\3.png
?????文件????????1535??2017-12-04?19:21??數字匹配\1_HelloOpenCV\4.png
?????文件????????1506??2017-12-04?19:22??數字匹配\1_HelloOpenCV\5.png
?????文件????????1907??2017-12-04?19:23??數字匹配\1_HelloOpenCV\6.png
?????文件????????1359??2017-12-04?19:24??數字匹配\1_HelloOpenCV\7.png
?????文件????????2020??2017-12-04?19:25??數字匹配\1_HelloOpenCV\8.png
?????文件????????1893??2017-12-04?19:26??數字匹配\1_HelloOpenCV\9.png
?????目錄???????????0??2018-05-26?15:36??數字匹配\1_HelloOpenCV\Debug\
?????文件??????272244??2014-07-24?17:19??數字匹配\1_HelloOpenCV\Debug\1.jpg
?????文件?????????406??2015-11-24?14:32??數字匹配\1_HelloOpenCV\Debug\1_HelloOpenCV.exe.em
?????文件?????????472??2017-02-24?20:14??數字匹配\1_HelloOpenCV\Debug\1_HelloOpenCV.exe.em
?????文件?????????381??2015-11-24?14:32??數字匹配\1_HelloOpenCV\Debug\1_HelloOpenCV.exe.intermediate.manifest
?????文件??????????81??2018-05-26?15:36??數字匹配\1_HelloOpenCV\Debug\1_HelloOpenCV.lastbuildstate
?????文件?????????938??2018-05-26?15:36??數字匹配\1_HelloOpenCV\Debug\1_HelloOpenCV.log
?????文件??????404185??2018-05-26?09:23??數字匹配\1_HelloOpenCV\Debug\1_HelloOpenCV.obj
?????文件?????????713??2017-02-17?10:53??數字匹配\1_HelloOpenCV\Debug\1_HelloOpenCV.vcxprojResolveAssemblyReference.cache
?????文件???????????0??2017-02-17?10:53??數字匹配\1_HelloOpenCV\Debug\1_HelloOpenCV.write.1.tlog
............此處省略100個文件信息
評論
共有 條評論