-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdf2score_detect.py
More file actions
79 lines (63 loc) · 2.68 KB
/
pdf2score_detect.py
File metadata and controls
79 lines (63 loc) · 2.68 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding:Utf-8 -*-
#!/usr/bin/env python
import cv2
import numpy as np
from operator import itemgetter, attrgetter, methodcaller
import xml.etree.ElementTree as ElementTree
from xml.dom import minidom
from xml.etree import ElementTree
from portees.pdf2score_portees import *
from mesures.pdf2score_mesures import *
from notes.pdf2score_notes import *
#-------------------------------------------------
#----------------- portees -----------------------
#-------------------------------------------------
nom_image='faure1'
img = cv2.imread(nom_image + ".jpg")
height, width = img.shape[:2]
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 120 #100
maxLineGap = 16 #10
lines = cv2.HoughLinesP(edges,1,np.pi/180,200,minLineLength,maxLineGap)
pdf2score_portees(nom_image, lines, height, width)
#-------------------------------------------------
#----------------- mesures -----------------------
#-------------------------------------------------
#img_rgb = cv2.imread('saintsaens.jpg')
#img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
threshold = 0.60
input_array = []
for i_temp in range(8):
template = cv2.imread('./motifs/0_barre' + str(i_temp + 1) + '.png',0)
res = cv2.matchTemplate(gray, template, cv2.TM_CCOEFF_NORMED)
loc = np.where(res > threshold)
input_array.append(loc)
width_template, height_template = template.shape[::-1]
width_partition, height_partition = gray.shape[::-1]
resMesures = pdf2score_mesures(nom_image, input_array, width_partition, width_template, height_template)
#-------------------------------------------------
#------------------ notes ------------------------
#-------------------------------------------------
threshold = 0.60
tabRes = []
template1 = cv2.imread('./motifs/elm_lily_note23_1.png',0)
res1 = cv2.matchTemplate(gray, template1, cv2.TM_CCOEFF_NORMED)
loc1 = np.where(res1 > threshold)
template2 = cv2.imread('./motifs/elm_lily_note23_2.png',0)
res2 = cv2.matchTemplate(gray, template2, cv2.TM_CCOEFF_NORMED)
loc2 = np.where(res2 > threshold)
template3 = cv2.imread('./motifs/elm_lily_note23_3.png',0)
res3 = cv2.matchTemplate(gray, template3, cv2.TM_CCOEFF_NORMED)
loc3 = np.where(res3 > threshold)
width_template1, height_template1 = template1.shape[::-1]
width_template2, height_template2 = template2.shape[::-1]
width_template3, height_template3 = template3.shape[::-1]
size_template= []
size_template.append(width_template1)
size_template.append(height_template1)
size_template.append(width_template2)
size_template.append(height_template2)
size_template.append(width_template3)
size_template.append(height_template3)
result = pdf2score_notes(nom_image, loc1, loc2, loc3, size_template)