forked from DDMAL/Rodan
/
barfinder.py
49 lines (40 loc) · 1.46 KB
/
barfinder.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
from rodan.jobs.utils import rodan_task
from rodan.celery_models.jobtype import JobType
from rodan.celery_models.jobbase import JobBase
from barfinder_resources.barfinder import BarlineFinder
from barfinder_resources.meicreate import BarlineDataConverter
import gamera.core
gamera.core.init_gamera()
@rodan_task(inputs=('tiff', 'txt'))
def barfinder(image_filepath, sg_hint_filepath, **kwargs):
input_image = gamera.core.load_image(image_filepath)
image_width = input_image.width
image_height = input_image.height
if input_image.resolution != 0:
image_dpi = input_image.resolution
else:
# set a default image dpi of 72
image_dpi = 72
# get the staff group hint inputted by the user
with open(sg_hint_filepath, 'r') as sg_file:
sg_hint = sg_file.read()
bar_finder = BarlineFinder()
staff_bb, bar_bb = bar_finder.process_file(input_image, sg_hint, image_dpi)
bar_converter = BarlineDataConverter(staff_bb, bar_bb)
bar_converter.bardata_to_mei(sg_hint, image_filepath, image_width, image_height, image_dpi)
mei_file = bar_converter.get_wrapped_mei()
return {
'mei': mei_file
}
class BarFinder(JobBase):
slug = 'bar-finder'
input_type = JobType.ROTATED_IMAGE
output_type = JobType.MEI
description = 'Find the bars in an image'
name = 'Bar Finder'
is_automatic = True
show_during_wf_create = True
parameters = {
}
task = barfinder
outputs_image = False