• 大小: 12.07MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-01
  • 语言: 其他
  • 标签: OpenCV  

资源简介

数码管数字识别,使用穿线法,检测八段数码管每一小段。OpenCV+VC2013.

资源截图

代码片段和文件信息

#include “algorithm.h“

bool IsAllWhite(Mat inputmat)
{
if (inputmat.rows * inputmat.cols == cvCountNonZero(&(IplImage)inputmat))
return true;
else
return false;
}

bool IsAllBlack(Mat inputmat)
{
if (cvCountNonZero(&(IplImage)inputmat) == 0)
return true;
else
return false;
}

/************   穿线法识别数码管数字  **********/
bool Iswhite(Mat inputmat int row_start int row_end int col_start int col_end)
{
int white_num = 0;
for (int i = row_start; i <= row_end; i++)
{
for (int j = col_start; j <= col_end; j++)
{
if (inputmat.at(i j) == 255)
white_num++;
//cout << white_num << endl;
}
}
if (white_num > 5)
return true;
else
return false;
}

int TubeIdentification(Mat inputmat) // 穿线法判断数码管a、b、c、d、e、f、g、
{
int tube = 0;
int tubo_roi[7][4] =
{
{ inputmat.rows * 0 / 3 inputmat.rows * 1 / 3 inputmat.cols * 1 / 2 inputmat.cols * 1 / 2 } // a
{ inputmat.rows * 1 / 3 inputmat.rows * 1 / 3 inputmat.cols * 2 / 3 inputmat.cols - 1     } // b
{ inputmat.rows * 2 / 3 inputmat.rows * 2 / 3 inputmat.cols * 2 / 3 inputmat.cols - 1     } // c
{ inputmat.rows * 2 / 3 inputmat.rows - 1     inputmat.cols * 1 / 2 inputmat.cols * 1 / 2 } // d
{ inputmat.rows * 2 / 3 inputmat.rows * 2 / 3 inputmat.cols * 0 / 3 inputmat.cols * 1 / 3 } // e
{ inputmat.rows * 1 / 3 inputmat.rows * 1 / 3 inputmat.cols * 0 / 3 inputmat.cols * 1 / 3 } // f
{ inputmat.rows * 1 / 3 inputmat.rows * 2 / 3 inputmat.cols * 1 / 2 inputmat.cols * 1 / 2 } // g
};

if (inputmat.rows / inputmat.cols > 2)   // 1 is specialwhich is much narrower than others
{
tube = 6;
}
else
{
for (int i = 0; i < 7; i++)
{

if (Iswhite(inputmat tubo_roi[i][0]  tubo_roi[i][1] tubo_roi[i][2] tubo_roi[i][3]))
tube = tube + (int)pow(2 i);
}
}

switch (tube)
{
case  63: return 0;  break;
case   6: return 1;  break;
case  91: return 2;  break;
case  79: return 3;  break;
case 102: return 4;  break;
case 109: return 5;  break;
case 125: return 6;  break;
case   7: return 7;  break;
case 127: return 8;  break;
case 111: return 9;  break;

default: return -1;
}
}

char trainfile[10];
void TraindataRead(Mat* traindata int traindatanum)
{
for (int i = 0; i < traindatanum; i++)
{
sprintf(trainfile “%d.bmp“ i);
cout << trainfile << endl;
traindata[i] = imread(trainfile 0);
threshold(traindata[i] traindata[i] 50 255 THRESH_BINARY);
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      13838  2017-03-14 21:25  TubeNumberIdentification\MeterIdentification\0.bmp

     文件       4198  2017-03-14 21:25  TubeNumberIdentification\MeterIdentification\1.bmp

     文件      12922  2017-03-14 21:21  TubeNumberIdentification\MeterIdentification\2.bmp

     文件      11794  2017-03-14 21:21  TubeNumberIdentification\MeterIdentification\3.bmp

     文件      11158  2017-03-14 21:21  TubeNumberIdentification\MeterIdentification\4.bmp

     文件      12358  2017-03-14 21:21  TubeNumberIdentification\MeterIdentification\5.bmp

     文件      12922  2017-03-14 21:21  TubeNumberIdentification\MeterIdentification\6.bmp

     文件      11566  2017-03-14 21:25  TubeNumberIdentification\MeterIdentification\7.bmp

     文件      12922  2017-03-14 21:21  TubeNumberIdentification\MeterIdentification\8.bmp

     文件      12922  2017-03-14 21:21  TubeNumberIdentification\MeterIdentification\9.bmp

     文件       2562  2017-03-17 16:59  TubeNumberIdentification\MeterIdentification\algorithm.cpp

     文件        461  2017-03-16 22:16  TubeNumberIdentification\MeterIdentification\algorithm.h

     文件        756  2017-03-14 14:01  TubeNumberIdentification\MeterIdentification\Debug\MeterIde.EA92F7C0.tlog\cl.command.1.tlog

     文件      24214  2017-03-14 14:01  TubeNumberIdentification\MeterIdentification\Debug\MeterIde.EA92F7C0.tlog\CL.read.1.tlog

     文件        518  2017-03-14 14:01  TubeNumberIdentification\MeterIdentification\Debug\MeterIde.EA92F7C0.tlog\CL.write.1.tlog

     文件          2  2017-03-12 14:58  TubeNumberIdentification\MeterIdentification\Debug\MeterIde.EA92F7C0.tlog\link.command.1.tlog

     文件          2  2017-03-12 14:58  TubeNumberIdentification\MeterIdentification\Debug\MeterIde.EA92F7C0.tlog\link.read.1.tlog

     文件          2  2017-03-12 14:58  TubeNumberIdentification\MeterIdentification\Debug\MeterIde.EA92F7C0.tlog\link.write.1.tlog

     文件        184  2017-03-14 14:01  TubeNumberIdentification\MeterIdentification\Debug\MeterIde.EA92F7C0.tlog\MeterIdentification.lastbuildstate

     文件          0  2017-03-14 14:01  TubeNumberIdentification\MeterIdentification\Debug\MeterIde.EA92F7C0.tlog\unsuccessfulbuild

     文件       2490  2017-03-14 14:01  TubeNumberIdentification\MeterIdentification\Debug\MeterIdentification.log

     文件      69386  2017-03-12 13:24  TubeNumberIdentification\MeterIdentification\Debug\test1.jpg

     文件      32734  2017-03-12 15:41  TubeNumberIdentification\MeterIdentification\Debug\test2.jpg

     文件      24684  2017-03-12 15:39  TubeNumberIdentification\MeterIdentification\Debug\test3.jpg

     文件     846848  2017-03-14 14:01  TubeNumberIdentification\MeterIdentification\Debug\vc120.idb

     文件    1937408  2017-03-14 14:01  TubeNumberIdentification\MeterIdentification\Debug\vc120.pdb

     文件       3016  2017-06-13 15:13  TubeNumberIdentification\MeterIdentification\loaction0.jpg

     文件       1529  2017-06-13 15:13  TubeNumberIdentification\MeterIdentification\loaction1.jpg

     文件       2802  2017-06-13 15:13  TubeNumberIdentification\MeterIdentification\loaction2.jpg

     文件       2479  2017-06-13 15:13  TubeNumberIdentification\MeterIdentification\loaction3.jpg

............此处省略83个文件信息

评论

共有 条评论