Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include "line_manipulation.h"
  2. #include "../utils.h"
  3. #include "../../list_manipulation/index.h"
  4. #include "../segmentation.h"
  5.  
  6. int get_words_space(SDL_Surface *image) {
  7. unsigned int max_count = 0;
  8. unsigned int min_count = image->w;
  9. unsigned int count = 0;
  10. for (int x = 0; x < image->w; ++x) {
  11.  
  12. if (is_blank_column(image, x)) {
  13. count++;
  14. } else {
  15. if (count > max_count)
  16. max_count = count;
  17. if (count < min_count)
  18. min_count = count;
  19. count = 0;
  20. }
  21. }
  22. return max_count - (min_count) / 2;
  23. }
  24.  
  25. List get_letters(SDL_Surface *image) {
  26. image = GetAllText(image, 10);
  27. List letters_list = create_list();
  28. int save_index = 0;
  29. for (int x = 0; x <= image->w; ++x) {
  30. //SDL_SaveBMP(image,"Coco1.jpg");
  31. if (is_blank_column(image, x) || x == image->w) {
  32. if (x == save_index) {
  33. save_index += 1;
  34. } else {
  35. letters_list = push_back_list(letters_list,
  36. (void *) CutImage(image, save_index, 0, x - save_index, image->h),
  37. ElementType);
  38. SDL_SaveBMP(image, "CurrentWord.jpg");
  39. SDL_SaveBMP(GetAllText(CutImage(image, save_index, 0, x - save_index, image->h), 10), "CurrentLetters.jpg");
  40. save_index = x + 1;
  41. }
  42. }
  43. }
  44. return letters_list;
  45. }
  46.  
  47. List get_words_and_letters(SDL_Surface *image) {
  48. image = GetAllText(image, 10);
  49. int space_limite = get_words_space(image)-6;
  50. space_limite -= (int)(space_limite* 0,1);
  51. // space_limite = (int) (space_limite *0,90);
  52. //SDL_SaveBMP(image,"Coco.jpg");
  53. // SDL_SaveBMP(GetAllText(image,10),"Cocospace.jpg");
  54.  
  55. List words_list = create_list();
  56. int save_index = 0;
  57. int blank_count = 0;
  58.  
  59. for (int x = 0; x <= image->w; ++x) {
  60. if (x != image->w && is_blank_column(image, x))
  61. blank_count += 1;
  62. else
  63. blank_count = 0;
  64. if (blank_count >= space_limite || x== image->w) {
  65. words_list = push_back_list(words_list,
  66. (void *) get_letters(CutImage(image, save_index, 0, x - save_index, image->h)),
  67. ListType);
  68. save_index = x + 1;
  69. blank_count = 0;
  70. }
  71. }
  72. return words_list;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement