Skip to content

Commit 5af68bf

Browse files
Kushal SaharanKushal Saharan
authored andcommitted
Comments added.
1 parent 7cd3cbe commit 5af68bf

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

frets.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#Called by the server to start a session
2+
#Defines the basic flow of execution of each session
3+
#inlcudes configuring the neck, playing and saving
4+
15
import lib
26
import cv2
37
import time
@@ -29,7 +33,7 @@ def configure():
2933

3034
time.sleep(1)
3135

32-
36+
#To get the strum direction and timing
3337
def start():
3438
ret, frame = vc.read()
3539

lib.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#Basic Library of Functions
2+
#To Identify Various Chords and Strums
3+
#Using openCV
4+
15
import cv2
26
import numpy as np
37
import play
@@ -6,24 +10,19 @@
610
neck_top=0
711
neck_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+
2018
strums = {
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

2827
notes_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'],
@@ -36,6 +35,8 @@
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+
3940
def 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

6251
def 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+
9283
def 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+
114107
def 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+
140135
def 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+
159156
def 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+
176175
def 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+
182183
def getDistance(positions):
183184
#Get Distance on the neck
184185
mean=0

play.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#Library to play the chords
2+
#and save the music files
3+
14
import subprocess
25
import decimal
36
import thread

0 commit comments

Comments
 (0)