markup: move functionality to library
This commit is contained in:
@ -1,7 +1,25 @@
|
||||
from markup.img import find_shapes, write_debug_image
|
||||
from markup.pdf import parse_pdf
|
||||
from markup.utils import overlaps
|
||||
|
||||
|
||||
def find_marked_products(pdf, subdir, catname, debug=0):
|
||||
"""Main entry point. Give a pdf, get matches."""
|
||||
(prods, scribbles) = parse_pdf(pdf, subdir, catname, debug)
|
||||
|
||||
if not prods or len(prods) < 1:
|
||||
print('no product placement markers found')
|
||||
return None
|
||||
|
||||
find_scribbles_shapes(scribbles)
|
||||
matches = find_matches(prods, scribbles, 0.10)
|
||||
|
||||
for s in scribbles:
|
||||
write_debug_image(subdir, catname, s['page'], prods, scribbles)
|
||||
|
||||
return matches
|
||||
|
||||
|
||||
def find_scribbles_shapes(scribbles):
|
||||
for scribble in scribbles:
|
||||
imgw, imgh, shapes = find_shapes(scribble['image'])
|
||||
@ -33,6 +51,7 @@ def find_matches(all_prods, scribbles, overlap_threshold):
|
||||
matches = []
|
||||
for s in scribbles:
|
||||
pagenum = s['page']
|
||||
if not pagenum in page_prods: continue
|
||||
prods = page_prods[pagenum]
|
||||
for p in prods:
|
||||
for box in s['bboxes']:
|
||||
|
||||
Reference in New Issue
Block a user