forked from johnoneil/MangaTextDetection
/
LocateText.py
executable file
·125 lines (81 loc) · 3.7 KB
/
LocateText.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#coding:utf8
#!/usr/bin/python
# vim: set ts=2 expandtab:
"""
Module: LocateText
Desc:
Author: John O'Neil
Email: oneil.john@gmail.com
DATE: Saturday, Sept 14th 2013
Setment raw manga scan and output image
with text areas outlined in red.
"""
#import clean_page as clean
import connected_components as cc
import run_length_smoothing as rls
import clean_page as clean
import ocr
import segmentation as seg
import furigana
import arg
import defaults
from scipy.misc import imsave
import numpy as np
import cv2
import sys
import argparse
import os
import scipy.ndimage
import datetime
if __name__ == '__main__':
print 'start....'
proc_start_time = datetime.datetime.now()
'''
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')
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)
segmented_image = seg.segment_image(gray)
cv2.imshow('segmented_image', segmented_image)
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)
outfile = 'img/no_equalizeHist.png'
#imsave(outfile, img)
cv2.imshow('result',img)
#cv2.imshow('segmented_image',segmented_image)
cv2.waitKey()
cv2.destroyAllWindows()
'''
if arg.boolean_value('display'):
cv2.imshow('segmented_image',segmented_image)
if cv2.waitKey(0) == 27:
cv2.destroyAllWindows()
cv2.destroyAllWindows()
'''