-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinference.py
59 lines (46 loc) · 1.76 KB
/
inference.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
import numpy as np
import cv2
from linefiller.trappedball_fill import trapped_ball_fill_multi, flood_fill_multi, mark_fill, build_fill_map, merge_fill, \
show_fill_map
from linefiller.thinning import thinning
import time
from log.logger import logger
import argparse
def processing(image:np.ndarray)->np.ndarray:
ret, binary = cv2.threshold(image, 220, 255, cv2.THRESH_BINARY)
fills = []
result = binary
fill = trapped_ball_fill_multi(result, 3, method='max')
fills += fill
result = mark_fill(result, fill)
fill = trapped_ball_fill_multi(result, 2, method='mean')
fills += fill
result = mark_fill(result, fill)
fill = trapped_ball_fill_multi(result, 1, method='mean')
fills += fill
result = mark_fill(result, fill)
fill = flood_fill_multi(result)
fills += fill
fillmap = build_fill_map(result, fills)
fillmap = merge_fill(fillmap)
return fillmap
def saveAll(fillmap:np.ndarray,PATH:str)->None:
# color+undertone
cv2.imwrite(PATH+'fills_merged.png', show_fill_map(fillmap))
# undertone
cv2.imwrite(PATH+'fills_merged_no_contour.png', show_fill_map(thinning(fillmap)))
def main()->None:
parser = argparse.ArgumentParser(description="Line Filler")
# args
parser.add_argument("-im","--image",type=str,help="Image Path",default="example.png")
parser.add_argument("-o","--output",type=str,help="Save Root Path", default="./")
args = parser.parse_args()
im = cv2.imread(args.image, cv2.IMREAD_GRAYSCALE)
logger.info("Start!")
start = time.time()
fillmap = processing(image=im)
saveAll(fillmap=fillmap,PATH=args.output)
logger.info("All Finished...")
logger.info(f"Total Running Time : {time.time() - start :.2f}sec")
if __name__ == "__main__":
main()