資源簡(jiǎn)介
opencv識(shí)別單行數(shù)字
代碼片段和文件信息
#include?“cv.h“
#include?“highgui.h“
#include?“cxcore.h“
#include?
using?namespace?std;
using?namespace?cv;
//寫本地日志,在原來(lái)的基礎(chǔ)上追加內(nèi)容!
void?savefile(CString??filename?char?*?info)
{
//將內(nèi)容寫至本地保存起來(lái)。。。
int?j?=?0;
char?ch[1000]?=?{?0?};
SYSTEMTIME?sys;
GetLocalTime(&sys);
j?=?sprintf(ch?“%s“?info);
j?+=?sprintf(ch?+?j?“\r\ntime:%02d/%02d?%02d:%02d:%02d.%03d?\r\n“?sys.wMonth?sys.wDay?sys.wHour?sys.wMinute?sys.wSecond?sys.wMilliseconds);
CFile?file;
file.Open(filename?CFile::modeCreate?|?CFile::modeWrite?|?CFile::modeNoTruncate?NULL);
file.SeekToEnd();
//file.Write(info?strlen(info));
file.Write(ch?j);
file.Close();
}
int?top?=?0?bottom?=?0;
int?itemp?=?0?ytemp?=?0;
int?secColValue?=?0;
void?cutTop(Mat&?src?Mat&?dstImg)//上下切割
{
bottom?=?src.rows;
int?i;
for?(i?=?0;?i? {
for?(size_t?j?=?0;?j? {
secColValue?+=?src.at(i?j);
}
if?(secColValue?>?0)
{
itemp?=?i;
break;
}
}
secColValue?=?0;
for?(int?k?=?itemp;?k? {
for?(size_t?y?=?0;?y? {
secColValue?+=?src.at(k?y);
}
if?(secColValue?<=?0)
{
ytemp?=?k;
break;
}
else
{
secColValue?=?0;
}
}
Rect?rect(0?itemp?src.cols?ytemp?-?itemp);
dstImg?=?src(rect).clone();
//imshow(“dstImg“?dstImg);
}
int?temp?=?0;
int?colValue?=?0;
int?colindex?=?0;
int?secindex?=?0;
int?srccols?=?0;
int?width?=?0;
int?iright?=?0;
//leftImg為左邊的圖片,rightImg為切割完之后剩下的右邊的圖片
int?cutLeft(Mat&?src?Mat&?leftImg?Mat&?rightImg)//左右切割
{
int?left?=?0;
int??right?=?0;
right?=?src.cols;
srccols?=?src.cols;
int?i;
for?(i?=?0;?i? {
colindex?=?i;
for?(size_t?j?=?0;?j? {
colValue?+=?src.at(j?i);
}
if?(colValue?>?0)
{
left?=?colindex;
temp?=?colindex;
break;
}
}
if?(left?==?0)
{
return?1;
}
colValue?=?0;
for?(int?j?=?temp;?j? {
//int?colValue?=?getColSum(src?j);
secindex?=?j;
for?(size_t?z?=?0;?z? {
colValue?+=?src.at(z?j);
}
if?(colValue?<=?0)
{
iright?=?secindex;
break;
}
else
{
colValue?=?0;
}
}
width?=?iright?-?temp;
Rect?rect(temp?0?width?src.rows);
leftImg?=?src(rect).clone();
//imshow(“l(fā)eftImg“?leftImg);
//waitKey(0);
Rect?rectRight(iright?0?src.cols?-?iright?src.rows);
rightImg?=?src(rectRight).clone();
cutTop(leftImg?leftImg);
//imshow(“dstImg“?leftImg);
return?0;
}
void?getPXSum(Mat?&src?int?&a)//獲取所有像素點(diǎn)和
{?
threshold(src?src?100?255?CV_THRESH_BINARY);
??a?=?0;
for?(int?i?=?0;?i? {
for?(int?j?=?0;?j? {
a?+=?src.at?(i?j);
}
}
}
int??getSubtract(Mat?&src?int?TemplateNum)?//兩張圖片相減
{
Mat?img_result;
int?min?=?1000000;
int?serieNum?=?0;
for?(int?i?=?0;?i?
評(píng)論
共有 條評(píng)論