📄 image.h
字号:
/****************************************************************************** * 光学字符识别程序 * 文件名:image.h * 功能 :图像处理相关函数定义 * modified by PRTsinghua@hotmail.com******************************************************************************/#ifndef IMAGE_H#define IMAGE_H#include <vector>#include <qpainter.h>#include <qdialog.h>#include "kognition.h"#include "segimage.h"#include "character.h"#include "abstract_character.h"#include "character_database.h"class Image : public QDialog{ Q_OBJECT private: static const float cs_angle_treshold; enum { max_iter = 5, seq_min_inner_threshold = 2, seq_min_outer_threshold = 4 }; public: Image( KognitionApp *parent = 0, const char *name = 0 ); ~Image(); enum drawing_flags { draw_border_lists = 0x00000001, draw_border_angles = 0x00000002, draw_border_angles_smooth = 0x00000004, draw_cross_sections = 0x00000008, draw_singular_regions = 0x00000010, draw_skeleton = 0x00000020, draw_directions = 0x00000040, draw_polygon_skeleton = 0x00000080, draw_grid = 0x00000100, draw_abstract_char = 0x00000200, draw_bw = 0x00000400, draw_guessed_lines = 0x00000800, draw_abstract_matching = 0x00001000 }; recognized_char_group recognize( const CharImage &char_scan, float base_line_pos, float reference_height, float angle ); abstract_character vectorize( const CharImage &char_scan, float base_line_pos, float reference_height, float angle ); float get_max_height( const CharImage &char_scan, float angle ); void build_cssg(); bool get_cross_point( const Segimage::point s, Segimage::point &e, float angle ); void set_draw_flag( drawing_flags flag, bool state ); void next_border_list( bool next ); void mark_next_cs( bool next ); void change_line_thickness( bool next ); void makeSnapshot(); void replace_char(); void append_variant_char(); protected: void paintEvent( QPaintEvent *e ); void mouseMoveEvent( QMouseEvent *e ); void keyPressEvent( QKeyEvent *e ); private: Image( const Image & ); // 构造函数 Image& operator=( const Image & ); // 复制操作符 static void drawFilledCircle( QPainter &p, const QPen &pen, int x, int y, int diameter, bool save_state ); static void setFillParameter( QPainter &p, const QPen &pen ); static void drawFilledCircleFast( QPainter &p, int x, int y, int diameter ); void drawRecognitionState( QPixmap &pix, float factor ); double direction( Segimage::point p ); double calc_dang( double prev, double curr ); bool need_no_smoothing( ringlist_iterator< Segimage::point > it ); void smooth_points( ringlist_iterator< Segimage::point > first, ringlist_iterator< Segimage::point > last, int num_points ); bool opposite_same_direction( ringlist_iterator< Segimage::point > &start_point ); int construct_sequence( ringlist_iterator< Segimage::point > &start_point, Segimage &simage, Segimage::cs_sequence &seq ); void detect_singular_region( Segimage::cs_sequence_start &csss, Segimage &simage, list< Segimage::singularpoint > &spl ); void clear(); float get_ratio(); int get_dpi_ratio( float dpi, float target_size_cm, bool is_height ); // debug view parameters unsigned int draw_flags; // 画图标识 int border_list_number; // 边界列表数目 int match_char_pos; int mark_cs; int pen_size; // 画笔大小 double avg_line_thickness; // 字符线条的平均粗细 CharImage scan; // 扫描进的字符 CharImage scan_bw; // 二值化图像 Segimage *segimage; // 字符的分割和交叉部分 Segimage::border_lists bl; // 边界列表 list<Segimage::cs_sequence> cssl; // 交叉序列列表 list<Segimage::singularpoint> spl; // 孤立点列表 character *skeleton; // 细化后的字符 abstract_character *abstract_char; // 归一化后的骨架 recognized_char_group char_group; // 已经识别的字符组 KognitionApp *app; signals: void setStatusMsg( const QString &str );};inline void Image::setFillParameter( QPainter &p, const QPen &pen ){ p.setPen( pen ); p.setBrush( QBrush( pen.color() ) );}inline void Image::drawFilledCircleFast( QPainter &p, int x, int y, int diameter ){ p.drawEllipse( x - diameter/2, y - diameter/2, diameter, diameter );}inline bool Image::need_no_smoothing( ringlist_iterator< Segimage::point > it ){ Segimage::point &p = *it; Segimage::point &p_next = *( ++it ); return ( p.dang <= 0 && p_next.dang <= 0 ) || ( p.dang >= 0 && p_next.dang >= 0 );}inline float Image::get_ratio(){ float factor_x = static_cast<float>( width() ) / scan.width(); float factor_y = static_cast<float>( height() ) / scan.height(); return ( factor_x < factor_y ) ? factor_x : factor_y;}inline int Image::get_dpi_ratio( float dpi, float target_size_cm, bool is_height ){ int dots = static_cast< int >( target_size_cm*dpi / 2.54 ); if ( is_height ) return dots / scan.height(); else return dots / scan.width();}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -