Giter Site home page Giter Site logo

zeinabtaghavi / handwriting_manuscript_line_and_segment_setection_then_storage Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 42.87 MB

License: MIT License

Python 100.00%
python opencv handwriting segmentation line-detection projection segment-detection manuscript hocr histogram

handwriting_manuscript_line_and_segment_setection_then_storage's Introduction

handwriting-Manuscript-_line_and_segment_detection_and_storage

this project has 2 main parts: 1- line detection, 2- segment detection in manuscript

why should we do it?(Despite the presence of hOCR)

in Persian and Arabic texts hocr is not strong enough to detect lines and words(especially when vowels are written like مَخصوصاً) this is hocr result line detection:

this is our code result line detection:

this is hocr result segment detection:

this is our code result segment detection:

describing code:

source image:

1- line detection:

by using x projection and then y projection we can find lines, in image what does it mean? read below:

# 2 - find the high compression vertical area

  vertical_hist = [sum(gray_env[i,:]) for i in range(img.shape[0])]
  

this is result of vertical_hist:

  vertical_temp = gray_corrected_rotation.copy()
  vertical_limit = gray_env.shape[1] * 255 * vertical_percent *.01
  for i in range(len(vertical_hist)):
      if vertical_hist[i] > vertical_limit:
          vertical_temp[i,:] = 255
      else:
          vertical_temp[i,:] = 0
          

this is result of mapping high density parts to be main lines:

it would give us a multimodal histogram, gets us height of lines.

then in each line, with same way we can find correct location of lines.

for y1,y2 in vertical_lines_positions:
      temp_img_env = gray_corrected_rotation_env[y1:y2,:]
      horizontal_limit = (y2-y1) * 255 * horizontal_percent * .01
      for j in range(temp_img_env.shape[1]):
          if sum(temp_img_env[:,j]) > horizontal_limit:
              line_location_image[y1:y2, j] = 0

then draw rectangle to bound them, and this is result:

adn one of the stored lines:

and then, we will store them in folder.

2- segment detection

at first, detect contours, in this time, may detect many noises, so whot to removethem? this is the histogram based on contours contourAre(lowest part is min contourAre and highest is biggest contourAre, in 10 bins):

the first bin has highest count of contoursArea, they are noises or dots, and must be ignored, then to cover all parts of segments(dots(like ب چ ج), vowels(like سَلام or بعضاً), and some seprate parts of one segments(like ک or گ )) detect first and last of width(w1, w1) then cover all heigh of line (h1 = 0 , h1 = height of line) then result is this image

and store them in a seprate file, some of example segments are:

handwriting_manuscript_line_and_segment_setection_then_storage's People

Contributors

zeinabtaghavi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

skyoflove1406

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.