Ejemplo n.º 1
0
def main():
    parser = arg.parser
    parser = argparse.ArgumentParser(
        description='Estimate areas of furigana in segmented raw manga scan.')
    parser.add_argument('infile',
                        help='Input (color) raw Manga scan image to clean.')
    parser.add_argument(
        'segmentation_file',
        help=
        'Input 3 channel segmentation of input image, with text areas in R channel.'
    )
    parser.add_argument('-o',
                        '--output',
                        dest='outfile',
                        help='Output (color) cleaned raw manga scan image.')
    #parser.add_argument('-m','--mask', dest='mask', default=None, help='Output (binary) mask for non-graphical regions.')
    #parser.add_argument('-b','--binary', dest='binary', default=None, help='Binarized version of input file.')
    parser.add_argument(
        '-v',
        '--verbose',
        help='Verbose operation. Print status messages during processing',
        action="store_true")
    parser.add_argument(
        '--display',
        help='Display output using OPENCV api and block program exit.',
        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('--segment_threshold', help='Threshold for nonzero pixels to separete vert/horiz text lines.',type=int,default=1)
    arg.value = parser.parse_args()

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

    if not os.path.isfile(infile) or not os.path.isfile(segmentation_file):
        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('\tWith segmentation file ' + segmentation_file)
        print('\tAnd generating output ' + outfile)

    furigana = estimate_furigana_from_files(infile, segmentation_file)

    imsave(outfile, furigana)

    if arg.boolean_value('display'):
        cv2.imshow('Furigana', furigana)
        if cv2.waitKey(0) == 27:
            cv2.destroyAllWindows()
        cv2.destroyAllWindows()
Ejemplo n.º 2
0
def main():
  parser = arg.parser
  parser = argparse.ArgumentParser(description='Segment raw Manga scan image.')
  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('-m','--mask', dest='mask', default=None, help='Output (binary) mask for non-graphical regions.')
  #parser.add_argument('-b','--binary', dest='binary', default=None, help='Binarized version of input file.')
  parser.add_argument('-v','--verbose', help='Verbose operation. Print status messages during processing', action="store_true")
  parser.add_argument('--display', help='Display output using OPENCV api and block program exit.', 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=float,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)
  parser.add_argument('--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 + '.segmented.png')
  binary_outfile = infile + '.binary.png'

  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)

  segmented = segment_image_file(infile)

  imsave(outfile,segmented)
  #cv2.imwrite(outfile,segmented)
  #if binary is not None:
  #  cv2.imwrite(binary_outfile, binary)

  if arg.boolean_value('display'):
    cv2.imshow('Segmented', segmented)
    #cv2.imshow('Cleaned',cleaned)
    #if args.mask is not None:
    #  cv2.imshow('Mask',mask)
    if cv2.waitKey(0) == 27:
      cv2.destroyAllWindows()
    cv2.destroyAllWindows()
Ejemplo n.º 3
0
def main(): 
  parser = arg.parser
  parser = argparse.ArgumentParser(description='Segment raw Manga scan image.')
  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('-m','--mask', dest='mask', default=None, help='Output (binary) mask for non-graphical regions.')
  #parser.add_argument('-b','--binary', dest='binary', default=None, help='Binarized version of input file.')
  parser.add_argument('-v','--verbose', help='Verbose operation. Print status messages during processing', action="store_true")
  parser.add_argument('--display', help='Display output using OPENCV api and block program exit.', 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=float,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)
  parser.add_argument('--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 + '.segmented.png')
  binary_outfile = infile + '.binary.png'

  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

  segmented = segment_image_file(infile)

  imsave(outfile,segmented)
  #cv2.imwrite(outfile,segmented)
  #if binary is not None:
  #  cv2.imwrite(binary_outfile, binary)
  
  if arg.boolean_value('display'):
    cv2.imshow('Segmented', segmented)
    #cv2.imshow('Cleaned',cleaned)
    #if args.mask is not None:
    #  cv2.imshow('Mask',mask)
    if cv2.waitKey(0) == 27:
      cv2.destroyAllWindows()
    cv2.destroyAllWindows()
Ejemplo n.º 4
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)
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def main():
  parser = arg.parser
  parser = argparse.ArgumentParser(description='Estimate areas of furigana in segmented raw manga scan.')
  parser.add_argument('infile', help='Input (color) raw Manga scan image to clean.')
  parser.add_argument('segmentation_file', help='Input 3 channel segmentation of input image, with text areas in R channel.')
  parser.add_argument('-o','--output', dest='outfile', help='Output (color) cleaned raw manga scan image.')
  #parser.add_argument('-m','--mask', dest='mask', default=None, help='Output (binary) mask for non-graphical regions.')
  #parser.add_argument('-b','--binary', dest='binary', default=None, help='Binarized version of input file.')
  parser.add_argument('-v','--verbose', help='Verbose operation. Print status messages during processing', action="store_true")
  parser.add_argument('--display', help='Display output using OPENCV api and block program exit.', 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('--segment_threshold', help='Threshold for nonzero pixels to separete vert/horiz text lines.',type=int,default=1)
  arg.value = parser.parse_args()

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

  if not os.path.isfile(infile) or not os.path.isfile(segmentation_file):
    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 '\tWith segmentation file ' + segmentation_file
    print '\tAnd generating output ' + outfile

  furigana = estimate_furigana_from_files(infile, segmentation_file)

  imsave(outfile,furigana)
  
  if arg.boolean_value('display'):
    cv2.imshow('Furigana', furigana)
    if cv2.waitKey(0) == 27:
      cv2.destroyAllWindows()
    cv2.destroyAllWindows()
Ejemplo n.º 7
0
    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('--segment_threshold', help='Threshold for nonzero pixels to separete vert/horiz text lines.',type=int,default=1)
    parser.add_argument(
        '--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))
Ejemplo n.º 8
0
    return temp_mask


if __name__ == '__main__':

  parser = arg.parser
  parser = argparse.ArgumentParser(description='Clean raw Manga scan image.')
  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('-m','--mask', dest='mask', default=None, help='Output (binary) mask for non-graphical regions.')
  parser.add_argument('-b','--binary', dest='binary', default=None, help='Binarized version of input file.')
  parser.add_argument('-v','--verbose', help='Verbose operation. Print status messages during processing', action="store_true")
  parser.add_argument('--display', help='Display output using OPENCV api and block program exit.', action="store_true")
  arg.value = parser.parse_args()

  infile = arg.string_value('infile')
  outfile = arg.string_value('outfile',default_value=infile + '.cleaned.png')
  binary_outfile = arg.string_value('binary',default_value=infile + '.binary.png')
  mask = arg.boolean_value('mask')

  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

  (binary,mask,cleaned) = clean_image_file(infile)

  cv2.imwrite(outfile,cleaned)
Ejemplo n.º 9
0
    #parser.add_argument('--segment_threshold', help='Threshold for nonzero pixels to separete vert/horiz text lines.',type=int,default=1)
    parser.add_argument(
        '--additional_filtering',
        help='Attempt to filter false text positives by histogram processing.',
        action="store_true")
    parser.add_argument('--bounding_boxes',
                        help="added bounding boxes for ocr regions",
                        type=bool,
                        default=False)
    parser.add_argument('--target_lang',
                        help="target language of translation,",
                        type=str,
                        default="en")
    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)
    translate_page(img,
                   boxes=arg.value.bounding_boxes,
                   target_lang=arg.string_value('target_lang'))
    cv2.imwrite(arg.string_value('outfile'), img)
    cv2.imshow("Hi", img)
    cv2.waitKey(0)
Ejemplo n.º 10
0
                        '--binary',
                        dest='binary',
                        default=None,
                        help='Binarized version of input file.')
    parser.add_argument(
        '-v',
        '--verbose',
        help='Verbose operation. Print status messages during processing',
        action="store_true")
    parser.add_argument(
        '--display',
        help='Display output using OPENCV api and block program exit.',
        action="store_true")
    arg.value = parser.parse_args()

    infile = arg.string_value('infile')
    outfile = arg.string_value('outfile',
                               default_value=infile + '.cleaned.png')
    binary_outfile = arg.string_value('binary',
                                      default_value=infile + '.binary.png')
    mask = arg.boolean_value('mask')

    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)
Ejemplo n.º 11
0
  parser = arg.parser
  parser = argparse.ArgumentParser(description='Generate HTML annotation for raw manga scan with detected OCR\'d text.')
  parser.add_argument('infile', help='Input (color) raw Manga scan image to annoate.')
  parser.add_argument('-o','--output', dest='outfile', help='Output html file.')
  parser.add_argument('-v','--verbose', help='Verbose operation. Print status messages during processing', action="store_true")
  parser.add_argument('--display', help='Display output using OPENCV api and block program exit.', action="store_true")
  parser.add_argument('--furigana', help='Attempt to suppress furigana characters which interfere with OCR.', 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('--segment_threshold', help='Threshold for nonzero pixels to separete vert/horiz text lines.',type=int,default=1)
  parser.add_argument('--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)