Skip to content

Commit

Permalink
rotation 180 degree for reversed images after detecting clef
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihal-Mansour committed Jan 28, 2021
1 parent f44965a commit fe73e53
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 25 deletions.
Binary file removed inputs/26.jpg
Binary file not shown.
Binary file removed inputs/30.jpg
Binary file not shown.
1 change: 1 addition & 0 deletions outputs/22.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
[ \meter<"4/2"> d1/4 d1/16 e1/8 e1/16 e1/32 {e1/4,g1/4} e1/4 e1/8 c1/8 g1/16 c1/16 e1/16],
[ \meter<"4/2"> {a1/4,d1/4,f1/4} a1/8 d1/8 c1/16 f1/16 d1/16 e1/16 c2/16 g2/16 d2/16 e2/16 {b1/4,f1/4,g1/4} c1/4 g1/4 a1/8 a1/32],
[ \meter<"4/2"> c1/16 d1/16 d1/16 e1/16 e1/4 e1/4 g1/4 e1/4 g1/4 d2/4]

}
2 changes: 1 addition & 1 deletion outputs/29.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[ \meter<"4/4">]
[ \meter<"4/4"> {c1/4} {d1/4} f1/2 g1/2 b1/8]
6 changes: 1 addition & 5 deletions outputs/30.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<<<<<<< HEAD
[
=======
[ \meter<"4/4">]
>>>>>>> e692483580c72e611518e04d6b8502194c5daf82
[ \meter<"4/4"> {c1/4} {d1/4} f1/2 g1/2 c2/8]
2 changes: 1 addition & 1 deletion outputs/31.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[ \meter<"4/4"> c1/8 g1/4 a1/4 b1/4]
[ \meter<"2/2">]
40 changes: 25 additions & 15 deletions src/deskewing/deskewing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,34 @@ def deskew(img,isSymbol=False,axis=1):
rotated = inter.rotate(img, trueAngle, reshape=True, order=0)
return rotated,trueAngle

def isReversed(segContours,maxSpace,maxLenStaffLines):
def isReversed(segContours,maxSpace,maxLenStaffLines,heights = []):
found = False
print(segContours)
print("maxLenStaffLines",maxLenStaffLines)
print("maxSpace",maxSpace)
for contour in segContours:
if(found == True):
break
for Xmin,Xmax,Ymin,Ymax in contour:
soulKeySearching = Ymax - Ymin

# detecting Soul Key
if (soulKeySearching > 6*maxSpace):
soulKeyDist = Xmin
found = True
if (len(heights) == 0):
for contour in segContours:
if(found == True):
break
for Xmin,Xmax,Ymin,Ymax in contour:
soulKeySearching = Ymax - Ymin

# detecting Soul Key
if (soulKeySearching > 6*maxSpace):
soulKeyDist = Xmin
found = True
break
else:
maxValue = 0
maxIndex = 0
indexInSeg = 0
#getting the clef in the first segment only
for H in heights[0]:
if H > maxValue:
maxValue = H
maxIndex = indexInSeg
indexInSeg+=1

#after detecting clef, now getting the xmin of this contour
soulKeyDist = segContours[0][maxIndex][0]

print("soulKeyDist",soulKeyDist)
if (soulKeyDist > 0.5 * maxLenStaffLines):
return True
else:
Expand Down
23 changes: 20 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from inout.generateOutput import *
from features.checkScanned import *
from features.extractfeatures import *
from deskewing.deskewing import *
import pickle
import os
import cv2
Expand All @@ -23,23 +24,39 @@
inputFolder = args.inputfolder
outputFolder = args.outputfolder

digitsFileModel = 'models/digits_model.sav'
symbolsFileModel = 'models/symbols_model.sav'
accedintalsFileModel = 'models/accedintals_model.sav'
digitsFileModel = '../models/digits_model.sav'
symbolsFileModel = '../models/symbols_model.sav'
accedintalsFileModel = '../models/accedintals_model.sav'

loaded_digits_model = pickle.load(open(digitsFileModel, 'rb'))
loaded_symbols_model = pickle.load(open(symbolsFileModel, 'rb'))
loaded_accedintals_model = pickle.load(open(accedintalsFileModel, 'rb'))

for fNum, filename in enumerate(os.listdir(inputFolder)):
binarizedImg = preprocessing(inputFolder + '/' + filename)
# copy is taken from binarized Image
binarizedImgCopy = np.copy(binarizedImg)
maxLenStaffLines = binarizedImg.shape[1]

heights = []
isHorizontal = getHorizontalLines(binarizedImg)
origImg=(binarizedImg*255).astype("uint8")
if(isHorizontal):
segContours, segContoursDim, maxSpace, checkNumList, segPeakMids, segWidths = staffRemoval(binarizedImg)
else:
segContours, segContoursDim, maxSpace, checkNumList, segPeakMids, segWidths, segAspects ,widths,heights,Ys= staffRemovalNonHorizontal(binarizedImg)

################check if image is reversed##############################
isImageReversed = isReversed(segContoursDim,maxSpace,maxLenStaffLines,heights)
if (isImageReversed == True):
rotatedImage = inter.rotate(binarizedImgCopy, 180, reshape=True, order=0)
isHorizontal = getHorizontalLines(rotatedImage)
origImg=(rotatedImage*255).astype("uint8")
if(isHorizontal):
segContours, segContoursDim, maxSpace, checkNumList, segPeakMids, segWidths = staffRemoval(rotatedImage)
else:
segContours, segContoursDim, maxSpace, checkNumList, segPeakMids, segWidths, segAspects ,widths,heights,Ys= staffRemovalNonHorizontal(rotatedImage)

outFileName = filename.split('.')[0]
f = open(outputFolder + '/' + outFileName+'.txt', "w")

Expand Down

0 comments on commit fe73e53

Please sign in to comment.