很惊喜地发现Jiri Matas的方法:Real-Time Scene TextLocalization and Recognition CVPR 2012 在OpenCV 3.0 的contrib中有实现,也许未来就会出现在OpenCV的正式版本中,太赞了,照源代码学习之!(四千多行代码,也是醉了~)
ERFilter源码地址:https://github.com/Itseez/opencv_contrib/tree/master/modules/text
我用VC2012创建的可以直接运行的Demo工程,CSDN下载:http://download.csdn.net/detail/liveintoday/8447045 (要用OpenCV 3.0,不过稍加修改2.4也能运行)
1.structCV_EXPORTSERStat 代码中用一个ERStat结构体来代表一个分类的极值区域
struct CV_EXPORTS ERStat
{
public:
//! Constructor
//explicit构造函数必须显式调用,将构造函数声明为explicit(显式)的方式可以抑制隐式转换。隐式转换常常带来程序逻辑的错误,而且这种错误一旦发生是很难察觉的。
explicit ERStat(int level = 256, int pixel = 0, int x = 0, int y = 0);
//! Destructor
~ERStat() { }
//! seed point and the threshold (max grey-level value)
int pixel;
int level;
// 这些特征的详细描述参加我学习笔记(三)中的图解
//! incrementally computable features
int area;
int perimeter;
int euler; //!< euler number
Rect rect;
double raw_moments[2]; //!< order 1 raw moments to derive the centroid
double central_moments[3]; //!< order 2 central moments to construct the covariance matrix
std::deque<int> *crossings;//!< horizontal crossings
float med_crossings; //!< median of the crossings at three different height levels
//! 2nd stage features
float hole_area_ratio;
float convex_hull_ratio;
float num_inflexion_points;
// TODO Other features can be added (average color, standard deviation, and such)
// TODO shall we include the pixel list whenever available (i.e. after 2nd stage) ?
std::vector<int> *pixels;
//! probability that the ER belongs to the class we are looking for
double probability;
//程序中用一个广搜删除ERStat区域树
//static void deleteERStatTree(ERStat* root) {
// queue<ERStat*> to_delete;
// to_delete.push(root);
// while (!to_delete.empty()) {
// ERStat* n = to_delete.front();
// to_delete.pop();
// ERStat* c = n->child;
// if (c != NULL) {
// to_delete.push(c);