/ocr/ocrservice/jni/hydrogen/src/hydrogentextdetector.h

http://eyes-free.googlecode.com/ · 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. #ifndef HYDROGEN_HYDROGENTEXTDETECTOR_H_
  17. #define HYDROGEN_HYDROGENTEXTDETECTOR_H_
  18. #include "leptonica.h"
  19. class HydrogenTextDetector {
  20. public:
  21. HydrogenTextDetector();
  22. ~HydrogenTextDetector();
  23. struct TextDetectorParameters {
  24. bool debug;
  25. char out_dir[255];
  26. // Edge-based thresholding
  27. l_int32 edge_tile_x;
  28. l_int32 edge_tile_y;
  29. l_int32 edge_thresh;
  30. l_int32 edge_avg_thresh;
  31. // Skew angle correction
  32. bool skew_enabled;
  33. l_float32 skew_min_angle;
  34. l_float32 skew_sweep_range;
  35. l_float32 skew_sweep_delta;
  36. l_int32 skew_sweep_reduction;
  37. l_int32 skew_search_reduction;
  38. l_float32 skew_search_min_delta;
  39. // Singleton filter
  40. l_float32 single_min_aspect;
  41. l_float32 single_max_aspect;
  42. l_int32 single_min_area;
  43. l_float32 single_min_density;
  44. // Quick pair filter
  45. l_float32 pair_h_ratio;
  46. l_float32 pair_d_ratio;
  47. l_float32 pair_h_dist_ratio;
  48. l_float32 pair_v_dist_ratio;
  49. l_float32 pair_h_shared;
  50. // Cluster pair filter
  51. l_int32 cluster_width_spacing;
  52. l_float32 cluster_shared_edge;
  53. l_float32 cluster_h_ratio;
  54. // Finalized cluster filter
  55. l_int32 cluster_min_blobs;
  56. l_float32 cluster_min_aspect;
  57. l_float32 cluster_min_fdr;
  58. l_int32 cluster_min_edge;
  59. l_int32 cluster_min_edge_avg;
  60. TextDetectorParameters()
  61. : debug(false),
  62. edge_tile_x(32),
  63. edge_tile_y(64),
  64. edge_thresh(64),
  65. edge_avg_thresh(4),
  66. skew_enabled(true),
  67. skew_min_angle(1.0),
  68. skew_sweep_range(30.0),
  69. skew_sweep_delta(5.0),
  70. skew_sweep_reduction(8),
  71. skew_search_reduction(4),
  72. skew_search_min_delta(0.01),
  73. single_min_aspect(0.1),
  74. single_max_aspect(4.0),
  75. single_min_area(4),
  76. single_min_density(0.2),
  77. pair_h_ratio(1.0),
  78. pair_d_ratio(1.5),
  79. pair_h_dist_ratio(2.0),
  80. pair_v_dist_ratio(0.25),
  81. pair_h_shared(0.25),
  82. cluster_width_spacing(2),
  83. cluster_shared_edge(0.5),
  84. cluster_h_ratio(1.0),
  85. cluster_min_blobs(5),
  86. cluster_min_aspect(2),
  87. cluster_min_fdr(2.5),
  88. cluster_min_edge(32),
  89. cluster_min_edge_avg(1)
  90. {
  91. }
  92. };
  93. // Function to set the original source image
  94. void SetSourceImage(PIX *);
  95. // Main text detection function
  96. void DetectText();
  97. // Clear recognition results between calls
  98. void Clear();
  99. // Function to return text area clippings of the original image
  100. PIXA *GetImageAreas();
  101. // Function to return binarized text areas
  102. PIXA *GetTextAreas();
  103. // Function to return text area confidences
  104. NUMA *GetTextConfs();
  105. // Function to return detected skew angle
  106. l_float32 GetSkewAngle();
  107. // Function to return the original source image
  108. PIX *GetSourceImage();
  109. TextDetectorParameters *GetMutableParameters();
  110. private:
  111. TextDetectorParameters parameters_;
  112. // Source image
  113. PIX *pixs_;
  114. // Detected text areas
  115. PIXA *text_areas_;
  116. // Confidences of detected text areas
  117. NUMA *text_confs_;
  118. // Detected skew angle
  119. l_float32 skew_angle_;
  120. // Function to extract text areas from a PIX
  121. PIXA *ExtractTextRegions(PIX *pix8, PIX *edges, NUMA **pconfs);
  122. // Function to detect and fix text skew
  123. PIX *DetectAndFixSkew(PIX *pixs);
  124. };
  125. #endif /* HYDROGEN_HYDROGENTEXTDETECTOR_H_ */