⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 character.cpp

📁 《Visual C++数字图像识别技术典型案例》之光学字符识别技术源码
💻 CPP
字号:
/****************************************************************************** * 光学字符识别程序 * 文件名:character.cpp * 功能  :字符类实现文件 * modified by PRTsinghua@hotmail.com******************************************************************************/#include <limits.h>#include <math.h>#include <ext/hash_map>#include <iostream>#include <complex>#include "common.h"#include "character.h"#include "image.h"#include "segimage.h"using std::max;const float character::md_threshold				= 0.15;const float character::md_compound_threshold	= 0.3;const float character::angle_treshold			= degtorad(180);const float character::acute_angle_threshold	= degtorad(95);const float character::straight_line_threshold_for_merge			= degtorad(10);const float character::straight_line_lower_threshold_for_intersect	= degtorad(15);const float character::straight_line_upper_threshold_for_intersect	= degtorad(165);const float character::straight_line_threshold	= degtorad(165);const float character::curve_to_line_ratio		= 2.0;const float character::threshold				= degtorad(2);const float character::lower_factor				= 0.2;const float character::smooth_iterations_factor	= 0.1;const int   character::lower_boundary			= 2;const int   character::sufficient_number		= 5;/****************************************************************************** * hash函数******************************************************************************/namespace __gnu_cxx {template<> struct hash< const Segimage::cs_sequence* >{	size_t operator()( const Segimage::cs_sequence* const & key ) const	{		return reinterpret_cast<size_t>(key);	// hash值是指针自己	}};}/****************************************************************************** * 构造函数******************************************************************************/character::character(const Segimage &segimage, 	list<Segimage::singularpoint> &spl_old) : line_thickness(0){	const float unset_angle=1000;	int num_cs=0;	hash_map<const Segimage::cs_sequence*, inner_sequence_start*, 		hash<const Segimage::cs_sequence*> > sequ;	#ifdef SPEED_MEASURE		struct timeval curtime;		seconds_passed(curtime);	#endif	segimage.get_bounding_box(min_x,max_x,min_y,max_y);	for(list<Segimage::singularpoint>::iterator i=spl_old.begin(); i!=spl_old.end(); ++i)	{		spl.push_back( singular_point() );		singular_point &sp=spl.back();				sp.x=i->x;		sp.y=i->y;		sp.area=i->pix_count;		if( i->cs_sequences.empty() || &(i->cs_sequences.front())==&(i->cs_sequences.back()) )			sp.type=end_point;		else if( &(*++(i->cs_sequences.begin()))==&(i->cs_sequences.back()) )			sp.type=turning_point;		else			sp.type=branching_point;					for(list<Segimage::cs_sequence_start>::iterator j=i->cs_sequences.begin(); j!=i->cs_sequences.end(); ++j)		{			sp.sequences.push_back( inner_sequence_start() );			inner_sequence_start &iss=sp.sequences.back();			if( !sequ[j->sequence] )			{				inner_sequence &is=*(new inner_sequence);				iss.sequence=&is;				iss.connect=new connection();				sequ[j->sequence]=&iss;												inner_point *last=NULL;				for(list<Segimage::point *>::iterator k=j->sequence->begin(); k!=j->sequence->end(); ++k)				{					inner_point ip;					ip.x=((*k)->x+(*k)->opp->x)/2.0;					ip.y=((*k)->y+(*k)->opp->y)/2.0;					float dx=(*k)->x-(*k)->opp->x;					float dy=(*k)->opp->y-(*k)->y;					line_thickness+=ip.thickness=sqrt(dx*dx+dy*dy);					num_cs++;					if( dx==0.0 )					{						if( dy==0.0 )						{							if( last!=NULL )							{								dx=ip.x-last->x;								dy=last->y-ip.y;								ip.direction=dx==0.0?M_PI_2:normalize_angle_pi(atan(dy/dx));							}							else								ip.direction=unset_angle;												}						else							ip.direction=0.0; // cross section is 90

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -