/ocr/ocrservice/jni/hydrogen/src/hydrogentextdetector.h
C++ Header | 151 lines | 90 code | 26 blank | 35 comment | 0 complexity | a353d48f1c4fa8ca8d63ea9ed1df60f4 MD5 | raw file
1/* 2 * Copyright 2010, Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef HYDROGEN_HYDROGENTEXTDETECTOR_H_ 18#define HYDROGEN_HYDROGENTEXTDETECTOR_H_ 19 20#include "leptonica.h" 21 22class HydrogenTextDetector { 23public: 24 HydrogenTextDetector(); 25 26 ~HydrogenTextDetector(); 27 28 struct TextDetectorParameters { 29 bool debug; 30 char out_dir[255]; 31 32 // Edge-based thresholding 33 l_int32 edge_tile_x; 34 l_int32 edge_tile_y; 35 l_int32 edge_thresh; 36 l_int32 edge_avg_thresh; 37 38 // Skew angle correction 39 bool skew_enabled; 40 l_float32 skew_min_angle; 41 l_float32 skew_sweep_range; 42 l_float32 skew_sweep_delta; 43 l_int32 skew_sweep_reduction; 44 l_int32 skew_search_reduction; 45 l_float32 skew_search_min_delta; 46 47 // Singleton filter 48 l_float32 single_min_aspect; 49 l_float32 single_max_aspect; 50 l_int32 single_min_area; 51 l_float32 single_min_density; 52 53 // Quick pair filter 54 l_float32 pair_h_ratio; 55 l_float32 pair_d_ratio; 56 l_float32 pair_h_dist_ratio; 57 l_float32 pair_v_dist_ratio; 58 l_float32 pair_h_shared; 59 60 // Cluster pair filter 61 l_int32 cluster_width_spacing; 62 l_float32 cluster_shared_edge; 63 l_float32 cluster_h_ratio; 64 65 // Finalized cluster filter 66 l_int32 cluster_min_blobs; 67 l_float32 cluster_min_aspect; 68 l_float32 cluster_min_fdr; 69 l_int32 cluster_min_edge; 70 l_int32 cluster_min_edge_avg; 71 72 TextDetectorParameters() 73 : debug(false), 74 edge_tile_x(32), 75 edge_tile_y(64), 76 edge_thresh(64), 77 edge_avg_thresh(4), 78 skew_enabled(true), 79 skew_min_angle(1.0), 80 skew_sweep_range(30.0), 81 skew_sweep_delta(5.0), 82 skew_sweep_reduction(8), 83 skew_search_reduction(4), 84 skew_search_min_delta(0.01), 85 single_min_aspect(0.1), 86 single_max_aspect(4.0), 87 single_min_area(4), 88 single_min_density(0.2), 89 pair_h_ratio(1.0), 90 pair_d_ratio(1.5), 91 pair_h_dist_ratio(2.0), 92 pair_v_dist_ratio(0.25), 93 pair_h_shared(0.25), 94 cluster_width_spacing(2), 95 cluster_shared_edge(0.5), 96 cluster_h_ratio(1.0), 97 cluster_min_blobs(5), 98 cluster_min_aspect(2), 99 cluster_min_fdr(2.5), 100 cluster_min_edge(32), 101 cluster_min_edge_avg(1) 102 { 103 } 104 }; 105 106 // Function to set the original source image 107 void SetSourceImage(PIX *); 108 109 // Main text detection function 110 void DetectText(); 111 112 // Clear recognition results between calls 113 void Clear(); 114 115 // Function to return text area clippings of the original image 116 PIXA *GetImageAreas(); 117 118 // Function to return binarized text areas 119 PIXA *GetTextAreas(); 120 121 // Function to return text area confidences 122 NUMA *GetTextConfs(); 123 124 // Function to return detected skew angle 125 l_float32 GetSkewAngle(); 126 127 // Function to return the original source image 128 PIX *GetSourceImage(); 129 130 TextDetectorParameters *GetMutableParameters(); 131 132private: 133 TextDetectorParameters parameters_; 134 135 // Source image 136 PIX *pixs_; 137 // Detected text areas 138 PIXA *text_areas_; 139 // Confidences of detected text areas 140 NUMA *text_confs_; 141 // Detected skew angle 142 l_float32 skew_angle_; 143 144 // Function to extract text areas from a PIX 145 PIXA *ExtractTextRegions(PIX *pix8, PIX *edges, NUMA **pconfs); 146 147 // Function to detect and fix text skew 148 PIX *DetectAndFixSkew(PIX *pixs); 149}; 150 151#endif /* HYDROGEN_HYDROGENTEXTDETECTOR_H_ */