Exemplo n.º 1
0
def translate_page(img,
                   binary_threshold=defaults.BINARY_THRESHOLD,
                   boxes=False,
                   target_lang="en"):
    gray = clean.grayscale(img)

    inv_binary = cv2.bitwise_not(
        clean.binarize(gray, threshold=binary_threshold))
    binary = clean.binarize(gray, threshold=binary_threshold)

    segmented_image = seg.segment_image(gray)
    segmented_image = segmented_image[:, :, 2]

    components = get_connected_components(segmented_image)

    for component in components:
        speech = img[component]
        if speech.shape[0] <= 0 or speech.shape[1] <= 0:
            continue
        translation = helper.ocr(speech, target_lang)
        if len(translation) > 0:
            #print "added component", translation
            white_out_text(img, component)
            add_text(img, component, translation)
    if boxes:
        cc.draw_bounding_boxes(img, components, color=(255, 0, 0), line_size=2)
    return img
Exemplo n.º 2
0
def main():
  parser = arg.parser
  parser = argparse.ArgumentParser(description='Basic OCR on raw manga scan.')
  parser.add_argument('infile', help='Input (color) raw Manga scan image to clean.')
  parser.add_argument('-o','--output', dest='outfile', help='Output (color) cleaned raw manga scan image.')
  parser.add_argument('-v','--verbose', help='Verbose operation. Print status messages during processing', action="store_true")
  #parser.add_argument('-d','--debug', help='Overlay input image into output.', action="store_true")
  parser.add_argument('--sigma', help='Std Dev of gaussian preprocesing filter.',type=float,default=None)
  parser.add_argument('--binary_threshold', help='Binarization threshold value from 0 to 255.',type=int,default=defaults.BINARY_THRESHOLD)
  parser.add_argument('--furigana', help='Attempt to suppress furigana characters to improve OCR.', action="store_true")
  parser.add_argument('--segment_threshold', help='Threshold for nonzero pixels to separete vert/horiz text lines.',type=int,default=defaults.SEGMENTATION_THRESHOLD)
  
  arg.value = parser.parse_args()
  
  infile = arg.string_value('infile')
  outfile = arg.string_value('outfile', default_value=infile + '.html')

  if not os.path.isfile(infile):
    print ('Please provide a regular existing input file. Use -h option for help.')
    sys.exit(-1)

  if arg.boolean_value('verbose'):
    print ('\tProcessing file ' + infile)
    print ('\tGenerating output ' + outfile)

  img = cv2.imread(infile)
  gray = clean.grayscale(img)
  binary = clean.binarize(gray)

  segmented = segmentation.segment_image_file(infile)

  components = cc.get_connected_components(segmented)

  #perhaps do more strict filtering of connected components because sections of characters
  #will not be dripped from run length smoothed areas? Yes. Results quite good.
  #filtered = cc.filter_by_size(img,components,average_size*100,average_size*1)

  blurbs = ocr_on_bounding_boxes(binary, components)
  for blurb in blurbs:
    print (str(blurb.x)+','+str(blurb.y)+' '+str(blurb.w)+'x'+str(blurb.h)+' '+ str(blurb.confidence)+'% :'+ blurb.text)
Exemplo n.º 3
0
def main():
  parser = arg.parser
  parser = argparse.ArgumentParser(description='Basic OCR on raw manga scan.')
  parser.add_argument('infile', help='Input (color) raw Manga scan image to clean.')
  parser.add_argument('-o','--output', dest='outfile', help='Output (color) cleaned raw manga scan image.')
  parser.add_argument('-v','--verbose', help='Verbose operation. Print status messages during processing', action="store_true")
  #parser.add_argument('-d','--debug', help='Overlay input image into output.', action="store_true")
  parser.add_argument('--sigma', help='Std Dev of gaussian preprocesing filter.',type=float,default=None)
  parser.add_argument('--binary_threshold', help='Binarization threshold value from 0 to 255.',type=int,default=defaults.BINARY_THRESHOLD)
  parser.add_argument('--furigana', help='Attempt to suppress furigana characters to improve OCR.', action="store_true")
  parser.add_argument('--segment_threshold', help='Threshold for nonzero pixels to separete vert/horiz text lines.',type=int,default=defaults.SEGMENTATION_THRESHOLD)
  
  arg.value = parser.parse_args()
  
  infile = arg.string_value('infile')
  outfile = arg.string_value('outfile', default_value=infile + '.html')

  if not os.path.isfile(infile):
    print 'Please provide a regular existing input file. Use -h option for help.'
    sys.exit(-1)

  if arg.boolean_value('verbose'):
    print '\tProcessing file ' + infile
    print '\tGenerating output ' + outfile

  img = cv2.imread(infile)
  gray = clean.grayscale(img)
  binary = clean.binarize(gray)

  segmented = segmentation.segment_image_file(infile)

  components = cc.get_connected_components(segmented)

  #perhaps do more strict filtering of connected components because sections of characters
  #will not be dripped from run length smoothed areas? Yes. Results quite good.
  #filtered = cc.filter_by_size(img,components,average_size*100,average_size*1)

  blurbs = ocr_on_bounding_boxes(binary, components)
  for blurb in blurbs:
    print str(blurb.x)+','+str(blurb.y)+' '+str(blurb.w)+'x'+str(blurb.h)+' '+ str(blurb.confidence)+'% :'+ blurb.text
Exemplo n.º 4
0
        '--additional_filtering',
        help='Attempt to filter false text positives by histogram processing.',
        action="store_true")
    arg.value = parser.parse_args()

    infile = arg.string_value('infile')
    outfile = arg.string_value('outfile',
                               default_value=infile + '.text_areas.png')

    if not os.path.isfile(infile):
        print(
            'Please provide a regular existing input file. Use -h option for help.'
        )
        sys.exit(-1)
    img = cv2.imread(infile)
    gray = clean.grayscale(img)

    binary_threshold = arg.integer_value(
        'binary_threshold', default_value=defaults.BINARY_THRESHOLD)
    if arg.boolean_value('verbose'):
        print('Binarizing with threshold value of ' + str(binary_threshold))
    inv_binary = cv2.bitwise_not(
        clean.binarize(gray, threshold=binary_threshold))
    binary = clean.binarize(gray, threshold=binary_threshold)

    segmented_image = seg.segment_image(gray)
    segmented_image = segmented_image[:, :, 2]
    components = cc.get_connected_components(segmented_image)
    cc.draw_bounding_boxes(img, components, color=(255, 0, 0), line_size=2)

    imsave(outfile, img)
Exemplo n.º 5
0
def estimate_furigana_from_files(filename, segmentation_filename):
  img = cv2.imread(filename)
  gray = clean.grayscale(img)
  seg = cv2.imread(segmentation_filename)
  segmentation = seg[:,:,2]
  return estimate_furigana(gray, segmentation)
def estimate_furigana_from_files(filename, segmentation_filename):
    img = cv2.imread(filename)
    gray = clean.grayscale(img)
    seg = cv2.imread(segmentation_filename)
    segmentation = seg[:, :, 2]
    return estimate_furigana(gray, segmentation)
Exemplo n.º 7
0
def segment_image_file(filename):
    img = cv2.imread(filename)
    gray = clean.grayscale(img)
    return segment_image(gray)
Exemplo n.º 8
0

    #infile = arg.string_value('infile')
    infile = r'img/same_text.png'
    #outfile = arg.string_value('outfile',default_value=infile + '.text_areas.png')
    
    
    if not os.path.isfile(infile):
        print 'Please provide a regular existing input file. Use -h option for help.'
        sys.exit(-1)
        
    img = cv2.imread(infile)
    cv2.imshow('srcimg', img)
    
    
    gray = clean.grayscale(img)
    
    

    binary_threshold = arg.integer_value('binary_threshold', default_value=defaults.BINARY_THRESHOLD)
    if arg.boolean_value('verbose'):
        print 'Binarizing with threshold value of ' + str(binary_threshold)
        
    
    
    inv_binary = cv2.bitwise_not(clean.binarize(gray, threshold=binary_threshold))
    #cv2.imshow('inv_binary', inv_binary)
    
    
    binary = clean.binarize(gray, threshold=binary_threshold)
    #cv2.imshow('binary', binary)
Exemplo n.º 9
0
def segment_image_file(filename):
  img = cv2.imread(filename)
  gray = clean.grayscale(img)
  return segment_image(gray)