-
Notifications
You must be signed in to change notification settings - Fork 0
/
pieces_of_code.py
46 lines (32 loc) · 1.46 KB
/
pieces_of_code.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
_27__only_staves = load_image(r"/Users/gabriel/Documents/imgs/pdf_to_tiff_conversion/IMG_test/Pitch_Recognition/127__only_staves.tiff")
musicstaves0 = musicstaves.MusicStaves_rl_fujinaga(_27__only_staves, 0, 0)
musicstaves0.remove_staves(u'all', 4)
# To retrieve the page position and dimensions of each one of the staves in a page
# using a MusicStaves object (actually removing the staves)
for i in range(1, len(musicstaves0.get_staffpos(x=0))):
print "Staff no.", i
musicstaves0.get_staffpos(x=0)[i].staffrect # staff position and dimension
musicstaves0.get_staffpos(x=0)[i].yposlist # each line position
# To retrieve the page position and dimensions of each one of the staves in a page
# using a StaffFinder object (without removing the staves)
from gamera.core import *
import gamera.toolkits.musicstaves
init_gamera()
image = load_image(r"/Users/gabriel/Documents/imgs/pdf_to_tiff_conversion/IMG_test/Pitch_Recognition/127__only_staves.tiff")
image = image.to_onebit()
sf = stafffinder_miyao.StaffFinder_miyao(image)
sf.find_staves()
staves = sf.get_average()
for i, staff in enumerate(staves):
print "Staff %d has %d staves:" % (i+1, len(staff))
for j, line in enumerate(staff):
print " %d. line at y-position:" % (j+1), line.average_y
# knn.glyphs_by_category
def glyphs_by_category(glyphs):
klasses = {}
for x in glyphs:
id = x.get_main_id()
if not klasses.has_key(id):
klasses[id] = []
klasses[id].append(x)
return klasses