Skip to content

Commit

Permalink
add testing for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
MulongXie committed Nov 11, 2020
1 parent 31ea025 commit f46c00c
Show file tree
Hide file tree
Showing 88 changed files with 592 additions and 578 deletions.
162 changes: 89 additions & 73 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified __pycache__/merge.cpython-35.pyc
Binary file not shown.
Binary file modified data/output/clips/Background/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/output/clips/Block/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/output/clips/Block/68.jpg
Binary file not shown.
Binary file removed data/output/clips/Block/69.jpg
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/output/clips/Compo/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/output/clips/Compo/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/output/clips/Compo/11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/output/clips/Compo/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/output/clips/Compo/14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/output/clips/Compo/15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/output/clips/Compo/17.jpg
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/output/clips/Compo/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/output/clips/Compo/20.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/output/clips/Compo/21.jpg
Binary file not shown.
Binary file removed data/output/clips/Compo/22.jpg
Binary file not shown.
Binary file removed data/output/clips/Compo/23.jpg
Binary file not shown.
Binary file removed data/output/clips/Compo/24.jpg
Binary file not shown.
Binary file removed data/output/clips/Compo/25.jpg
Binary file not shown.
Binary file removed data/output/clips/Compo/30.jpg
Binary file not shown.
Binary file removed data/output/clips/Compo/31.jpg
Binary file not shown.
Binary file removed data/output/clips/Compo/32.jpg
Binary file not shown.
Binary file removed data/output/clips/Compo/33.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/34.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/36.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/37.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/38.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/39.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/46.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/48.jpg
Diff not rendered.
Binary file modified data/output/clips/Compo/5.jpg
Binary file removed data/output/clips/Compo/50.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/52.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/54.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/56.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/59.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/61.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/63.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/65.jpg
Diff not rendered.
Binary file removed data/output/clips/Compo/67.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/0.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/10.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/11.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/12.jpg
Diff not rendered.
Binary file added data/output/clips/Text/16.jpg
Binary file removed data/output/clips/Text/18.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/26.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/27.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/29.jpg
Diff not rendered.
Binary file added data/output/clips/Text/3.jpg
Binary file removed data/output/clips/Text/40.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/41.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/42.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/43.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/44.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/45.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/47.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/49.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/51.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/53.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/55.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/57.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/58.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/60.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/62.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/64.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/66.jpg
Diff not rendered.
Binary file removed data/output/clips/Text/8.jpg
Diff not rendered.
Binary file modified data/output/clips/Text/9.jpg
Binary file modified data/output/clips/bkg.png
480 changes: 179 additions & 301 deletions data/output/compo.json

Large diffs are not rendered by default.

442 changes: 276 additions & 166 deletions data/output/ip/472.json

Large diffs are not rendered by default.

Binary file modified data/output/ip/result.jpg
Binary file modified data/output/result.jpg
21 changes: 11 additions & 10 deletions merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def rm_compos_in_text(compos):


def incorporate(img_path, compo_path, text_path, output_root, params,
resize_by_height=None, show=False):
resize_by_height=None, show=False, wait_key=0):
org = cv2.imread(img_path)

compos = []
Expand All @@ -118,29 +118,30 @@ def incorporate(img_path, compo_path, text_path, output_root, params,
texts.append(element)

org_resize = resize_img_by_height(org, resize_by_height)
draw_bounding_box_class(org_resize, compos, show=show, name='ip')
draw_bounding_box(org_resize, texts, show=show, name='ocr')
draw_bounding_box_class(org_resize, compos, show=show, name='ip', wait_key=wait_key)
draw_bounding_box(org_resize, texts, show=show, name='ocr', wait_key=wait_key)

compos_merged = reclassify_text_by_ocr(org_resize, compos, texts)
# compos_merged = merge_redundant_corner(org_resize, compos_merged)
draw_bounding_box_class(org_resize, compos_merged, name='text', show=show)
# draw_bounding_box_class(org_resize, compos_merged, name='text', show=show, wait_key=wait_key)

# merge words as line
compos_merged = merge_intersected_compos(org_resize, compos_merged, max_gap=(params['max-word-inline-gap'], 0), merge_class='Text')
draw_bounding_box_class(org_resize, compos_merged, name='merged line', show=show)
draw_bounding_box_class(org_resize, compos_merged, name='merged line', show=show, wait_key=wait_key)
# merge lines as paragraph
compos_merged = merge_intersected_compos(org_resize, compos_merged, max_gap=(0, params['max-line-gap']), merge_class='Text')
draw_bounding_box_class(org_resize, compos_merged, name='merged paragraph', show=show)
# draw_bounding_box_class(org_resize, compos_merged, name='merged paragraph', show=show)
# clean compos intersected with paragraphs
compos_merged = rm_compos_in_text(compos_merged)
board = draw_bounding_box_class(org_resize, compos_merged, name='merged paragraph', is_return=True, show=show)
board = draw_bounding_box_class(org_resize, compos_merged, name='merged paragraph', is_return=True, show=show, wait_key=wait_key)

draw_bounding_box_non_text(org_resize, compos_merged, org_shape=org.shape, show=show)
# draw_bounding_box_non_text(org_resize, compos_merged, org_shape=org.shape, show=show)
compos_json = save_corners_json(output_root, background, compos_merged, org_resize.shape)
dissemble_clip_img_fill(pjoin(output_root, 'clips'), org_resize, compos_json)
cv2.imwrite(pjoin(output_root, 'result.jpg'), board)

print('Merge Complete and Save to', pjoin(output_root, 'result.jpg'))
print(time.ctime(), '\n')
if show:
cv2.destroyAllWindows()
# if show:
# cv2.destroyAllWindows()

8 changes: 4 additions & 4 deletions run_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ def resize_height_by_longest_edge(img_path, resize_length=800):
mobile: {'min-grad':4, 'ffl-block':5, 'min-ele-area':50, 'max-word-inline-gap':6, 'max-line-gap':1}
web : {'min-grad':3, 'ffl-block':5, 'min-ele-area':25, 'max-word-inline-gap':4, 'max-line-gap':4}
'''
key_params = {'min-grad':10, 'ffl-block':5, 'min-ele-area':50, 'merge-contained-ele':True,
key_params = {'min-grad':4, 'ffl-block':5, 'min-ele-area':50, 'merge-contained-ele':True,
'max-word-inline-gap':4, 'max-line-gap':4}

# set input image path
input_path_img = 'data/input/30800.jpg'
input_path_img = 'data/input/472.jpg'
output_root = 'data/output'

resized_height = resize_height_by_longest_edge(input_path_img)

is_ip = True
is_ip = False
is_clf = False
is_ocr = False
is_merge = False
is_merge = True

if is_ocr:
import detect_text_east.ocr_east as ocr
Expand Down
46 changes: 26 additions & 20 deletions run_testing(Used for Adjusting).py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def resize_height_by_longest_edge(img_path, resize_length=800):
return int(resize_length * (height / width))


def nothing(x):
pass


if __name__ == '__main__':

'''
Expand All @@ -35,16 +39,12 @@ def resize_height_by_longest_edge(img_path, resize_length=800):
'max-word-inline-gap':4, 'max-line-gap':4}

# set input image path
input_path_img = 'data/input/30800.jpg'
input_path_img = 'data/input/472.jpg'
output_root = 'data/output'

resized_height = resize_height_by_longest_edge(input_path_img)

is_ip = True
is_clf = False
is_ocr = False
is_merge = False

if is_ocr:
import detect_text_east.ocr_east as ocr
import detect_text_east.lib_east.eval as eval
Expand All @@ -53,38 +53,44 @@ def resize_height_by_longest_edge(img_path, resize_length=800):
ocr.east(input_path_img, output_root, models, key_params['max-word-inline-gap'],
resize_by_height=resized_height, show=False)

'''
******** Testing with adjustable parameters ********
'''
testing_ip = False
testing_merge = True

def nothing(x):
pass
cv2.namedWindow('parameters')
cv2.createTrackbar('min-grad', 'parameters', 4, 20, nothing)
cv2.createTrackbar('min-ele-area', 'parameters', 20, 200, nothing)

while(1):
key_params['min-grad'] = cv2.getTrackbarPos('min-grad', 'parameters')
key_params['min-ele-area'] = cv2.getTrackbarPos('min-ele-area', 'parameters')

if is_ip:
if testing_ip:
cv2.createTrackbar('min-grad', 'parameters', 4, 20, nothing)
cv2.createTrackbar('min-ele-area', 'parameters', 20, 200, nothing)
while(1):
key_params['min-grad'] = cv2.getTrackbarPos('min-grad', 'parameters')
key_params['min-ele-area'] = cv2.getTrackbarPos('min-ele-area', 'parameters')
import detect_compo.ip_region_proposal as ip
os.makedirs(pjoin(output_root, 'ip'), exist_ok=True)
# switch of the classification func
classifier = None
if is_clf:
classifier = {}
from cnn.CNN import CNN

# classifier['Image'] = CNN('Image')
classifier['Elements'] = CNN('Elements')
# classifier['Noise'] = CNN('Noise')
ip.compo_detection(input_path_img, output_root, key_params,
classifier=classifier, resize_by_height=resized_height, show=True, wai_key=None)

if is_merge:
cv2.waitKey(10)

if testing_merge:
cv2.createTrackbar('max-word-inline-gap', 'parameters', 4, 20, nothing)
cv2.createTrackbar('max-line-gap', 'parameters', 20, 200, nothing)
while(1):
key_params['max-word-inline-gap'] = cv2.getTrackbarPos('max-word-inline-gap', 'parameters')
key_params['max-line-gap'] = cv2.getTrackbarPos('max-line-gap', 'parameters')
import merge
name = input_path_img.split('/')[-1][:-4]
compo_path = pjoin(output_root, 'ip', str(name) + '.json')
ocr_path = pjoin(output_root, 'ocr', str(name) + '.json')
merge.incorporate(input_path_img, compo_path, ocr_path, output_root, params=key_params,
resize_by_height=resized_height, show=True)
resize_by_height=resized_height, show=True, wait_key=None)
cv2.waitKey(10)

cv2.waitKey(10)
Binary file modified utils/__pycache__/util_merge.cpython-35.pyc
Binary file not shown.
11 changes: 7 additions & 4 deletions utils/util_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
C = Config()


def draw_bounding_box_class(org, compos, color_map=C.COLOR, line=2, show=False, is_return=False, name='img'):
def draw_bounding_box_class(org, compos, color_map=C.COLOR, line=2,
show=False, is_return=False, name='img', wait_key=0):
if not show and not is_return: return
board = org.copy()

Expand All @@ -29,18 +30,20 @@ def draw_bounding_box_class(org, compos, color_map=C.COLOR, line=2, show=False,
# cv2.FONT_HERSHEY_SIMPLEX, 0.5, class_colors[compo_class[i]], 2)
if show:
cv2.imshow(name, board)
cv2.waitKey(0)
if wait_key is not None:
cv2.waitKey(wait_key)
return board


def draw_bounding_box(org, compos, color=(0, 255, 0), line=2, show=False, name='board'):
def draw_bounding_box(org, compos, color=(0, 255, 0), line=2, show=False, name='board', wait_key=0):
board = org.copy()
for compo in compos:
corner = compo.put_bbox()
board = cv2.rectangle(board, (corner[0], corner[1]), (corner[2], corner[3]), color, line)
if show:
cv2.imshow(name, board)
cv2.waitKey(0)
if wait_key is not None:
cv2.waitKey(wait_key)
return board


Expand Down

0 comments on commit f46c00c

Please sign in to comment.