1+ #Basic Library of Functions
2+ #To Identify Various Chords and Strums
3+ #Using openCV
4+
15import cv2
26import numpy as np
37import play
610neck_top = 0
711neck_bottom = 500
812
9- """
10- strums = [
11- ['A', 'E4 C#3 A4 E3 A2 E2'],
12- ['C', 'E4 C3 G3 E3 C2 E2'],
13- ['D', 'F#4 D3 A4 D3 A2 E2'],
14- ['E', 'E4 B3 G#3 E3 B2 E2'],
15- ['G', 'G4 B3 G3 D3 B2 G2']]
16- """
1713
1814#(post_fix_num,note)
1915
16+ #Notes making each chords in Standard Guitar Tuning
17+
2018strums = {
2119 'A' : [(3 ,7 ),(2 ,4 ),(3 ,0 ),(2 ,7 ),(1 ,0 ),(1 ,7 )],
2220 'C' : [(3 ,7 ),(2 ,3 ),(10 ,2 ),(2 ,7 ),(1 ,3 ),(1 ,7 )],
2321 'D' : [(3 ,9 ),(2 ,5 ),(3 ,0 ),(2 ,5 ),(1 ,0 ),(1 ,7 )],
2422 'E' : [(3 ,7 ),(2 ,2 ),(2 ,11 ),(2 ,7 ),(1 ,2 ),(1 ,7 )],
2523 'G' : [(3 ,10 ),(2 ,2 ),(2 ,10 ),(2 ,5 ),(1 ,2 ),(1 ,10 )]}
2624
25+ #Array to go over each note in case of fret shift
2726
2827notes_ar = [['A1' ,'A#1' ,'B1' ,'C1' ,'C#1' ,'D1' ,'D#1' ,'E1' ,'F1' ,'F#1' ,'G1' ,'G#1' ],
2928 ['A2' ,'A#2' ,'B2' ,'C2' ,'C#2' ,'D2' ,'D#2' ,'E2' ,'F2' ,'F#2' ,'G2' ,'G#2' ],
3635 [(60 , 90 ),(81 , 255 ),(0 , 255 )], # Green
3736 [(100 , 119 ),(136 , 255 ),(0 , 255 )]] # Blue
3837
38+ #Clear noise when reading image contours
39+
3940def clearNoise (img ):
4041 kernel = np .ones ((10 , 10 ), np .uint8 )
4142 clrimg = cv2 .morphologyEx (img , cv2 .MORPH_CLOSE , kernel )
@@ -45,19 +46,7 @@ def clearNoise(img):
4546 # Clears noise from image
4647 return clrimg
4748
48- def get_strum (mode , direction ):
49- if direction == 'up' :
50- for row in strums :
51- if row [0 ] == mode :
52- return row [1 ]
53- else :
54- for row in strums :
55- if row [0 ] == mode :
56- rev = ""
57- _array = row [1 ].split (" " )
58- for row2 in reversed (_array ):
59- rev += row2 + " "
60- return rev [:- 1 ]
49+ #Filter Out Each ColorBand covered Finger
6150
6251def filterFingers (img ):
6352
@@ -89,6 +78,8 @@ def filterFingers(img):
8978 # Returns an array of three filtered fingers images
9079 return fingerArray
9180
81+ #Get coordinates of each fingers/bands topmost point
82+
9283def getPositions (imgArray ):
9384 # Returns the topmost points of filtered blobs from given imgs
9485
@@ -111,6 +102,8 @@ def getPositions(imgArray):
111102
112103 return positions
113104
105+ #Find the Chords to be played based on finger orientation
106+
114107def getMode (positionArray ):
115108 # Finds mode using by filtering three color strips and finding positions
116109
@@ -137,6 +130,8 @@ def getMode(positionArray):
137130
138131 return mode
139132
133+ #Keep tab of strumming hand
134+
140135def getLowerBlob (img ):
141136 # Filters lower blob and returns position
142137 position = (0 , 0 )
@@ -156,6 +151,8 @@ def getLowerBlob(img):
156151
157152 return position
158153
154+ #Generate notes combination based on fret shift, strum direction, chord
155+
159156def getPattern (mode ,dist ,direction ):
160157 pattern = ''
161158 for note in strums [mode ]:
@@ -173,12 +170,16 @@ def getPattern(mode,dist,direction):
173170 rev += row2 + " "
174171 return rev [:- 1 ]
175172
173+ #Init neck size
174+
176175def initNeck (top ,bottom ):
177176 #Initialize the neck length
178177 neck_len = (top [0 ]- bottom [0 ][0 ])/ 2
179178 neck_bottom = bottom [0 ][0 ]
180179 neck_top = top [0 ]
181180
181+ #get fret shift
182+
182183def getDistance (positions ):
183184 #Get Distance on the neck
184185 mean = 0
0 commit comments