def prepare_sharps(image): image_gray = img_fun.image_gray(image) image_bin = img_fun.image_bin(image_gray) image_bin = img_fun.invert(image_bin) image_bin = cv2.erode(image_bin,np.ones((1,3)),iterations=1)
def get_notes(image): gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, image_bin = cv2.threshold(gray, 180, 255, cv2.THRESH_BINARY) image_bin=img_fun.invert(image_bin) horizontalsize = 200; horizontalStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (horizontalsize, 1)); image_bin = cv2.erode(image_bin, horizontalStructure, iterations=1) image_bin = cv2.dilate(image_bin,horizontalStructure, iterations=1) image_orig, selected_regions, lines = select_horizontal_lines(image.copy(), image_bin) #cv2.imshow('lines', image_orig) lines,groups = add_additional_lines(lines) sheet = chp.get_note_positions(image,groups) notes = [] #notes = generate_notes(lines, positions) return sheet
def __init__(self,image): self.image = image image_gray = img_fun.image_gray(image) ret, self.image_bin = cv2.threshold(image_gray, 150, 255, cv2.THRESH_BINARY) self.image_bin = img_fun.invert(self.image_bin) self.remove_accs()
def prepare_bar_lines(image): image_gray = img_fun.image_gray(image) image_bin = img_fun.image_bin(image_gray) image_bin = img_fun.invert(image_bin) # cv2.imshow('bar lines',image_bin) return image_bin
def prepare_half_notes(image): image_gray = img_fun.image_gray(image) image_bin = img_fun.image_bin(image_gray) image_bin = cv2.morphologyEx(image_bin, cv2.MORPH_OPEN, np.ones((4,4))) image_bin = cv2.erode(image_bin,np.ones((2,2)),iterations=1) image_bin = img_fun.invert(image_bin) return image_bin
def get_note_positions(image,groups): image_gray = img_fun.image_gray(image) image_bin = img_fun.image_bin(image_gray) image_bin = img_fun.invert(image_bin) image_bin = cv2.dilate(image_bin, np.ones((6,2)), iterations=1) verticalSize = 4; verticalStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (verticalSize,1)); image_bin = cv2.erode(image_bin, verticalStructure, iterations=1) image_bin = cv2.erode(image_bin, np.ones((7,1)), iterations=1) #image_bin = cv2.dilate(image_bin, np.ones((6,2)), iterations=1) #image_bin = img_fun.erode(image_bin) #image_bin = disconnect_note_heads(image.copy(), image_bin) # image_bin = cv2.erode(image_bin, verticalStructure, iterations=1) # image_bin = cv2.erode(image_bin, verticalStructure, iterations=3) # image_bin = disconnect_note_heads(image.copy(), image_bin) # # image_bin = cv2.erode(image_bin, np.ones((2,2)), iterations=1) # image_bin = img_fun.dilate(image_bin) # kernel = np.ones((3,3)) # strukturni element 3x3 blok # # image_bin = img_fun.dilate(image_bin) # #image_bin = img_fun.dilate(image_bin) # # kernel_vet = np.ones((6,1)) # kernel_hor = np.ones((1,5)) # image_bin = cv2.erode(image_bin, kernel_hor, iterations=1) # image_bin = cv2.dilate(image_bin, kernel_vet, iterations=1) # # image_bin = cv2.dilate(image_bin, kernel, iterations=1) # #image_bin = cv2.erode(image_bin, kernel, iterations=1) cv2.imshow('preparet image', image_bin) image_orig,selected_regions, positions = select_note_heads(image.copy(), image_bin, groups) cv2.imshow('asd', image_orig) return positions
def prepare_whole_notes(image): image_gray = img_fun.image_gray(image) image_bin = img_fun.image_bin(image_gray) # image_bin = cv2.erode(image_bin,np.ones((1,2)),iterations=3) # # image_bin = cv2.dilate(image_bin,np.ones((2,4)),iterations=2) image_bin = img_fun.invert(image_bin) # img_fun.show_image('whole_gray',image_gray) # img_fun.show_image('whole_bin',image_bin) return image_bin
def get_groups(self,image): gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, image_bin = cv2.threshold(gray, 180, 255, cv2.THRESH_BINARY) image_bin=img_fun.invert(image_bin) horizontalsize = 200; horizontalStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (horizontalsize, 1)); image_bin = cv2.erode(image_bin, horizontalStructure, iterations=1) image_bin = cv2.dilate(image_bin,horizontalStructure, iterations=1) image_orig, selected_regions, lines = nt_fun.select_horizontal_lines(image.copy(), image_bin) lines,groups = nt_fun.add_additional_lines(lines) return groups
def prepare_quarter_notes(image): image_gray = img_fun.image_gray(image) image_bin = img_fun.image_bin(image_gray) # img_fun.show_image(image_bin) # img_fun.show_image(image_gray) image_bin = img_fun.invert(image_bin) verticalSize = 3; horSize = 3 verticalStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (verticalSize,1)); horStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (1,horSize)); image_bin = cv2.erode(image_bin, verticalStructure, iterations=1) image_bin = cv2.morphologyEx(image_bin, cv2.MORPH_OPEN, np.ones((5,5))) image_bin = disconnect_note_heads(image.copy(),image_bin) # cv2.imshow('quarter bin',image_bin) return image_bin
from sklearn import datasets from sklearn.cluster import KMeans import ann_functions as ann_fun import imageProcessingFunctions as imgFunctions import note_positions_fun as np_fun import soundGenerator as sgen image = cv2.imread("images/sheet4.png") gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, image_bin = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY) image_bin = imgFunctions.invert(image_bin) image_orig, selected_regions, positions = imgFunctions.select_roi(image.copy(), image_bin) positions = np.array(positions).reshape(len(positions), 1) print positions """ k_means = KMeans(n_clusters=8, max_iter=5000, init='random', tol=0.00001, n_init=10) k_means.fit(positions) print k_means.cluster_centers_ """ cv2.imshow("binary", image_orig) cv2.waitKey(0)
import cv2 import numpy as np import matplotlib.pyplot as plt import imageProcessingFunctions as img_fun import collections import note_head_position import note as nt import soundGenerator as sgen image = cv2.imread("images/sheet6.png") gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, image_bin = cv2.threshold(gray, 180, 255, cv2.THRESH_BINARY) image_bin=img_fun.invert(image_bin) horizontalsize = 200; horizontalStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (horizontalsize, 1)); image_bin = cv2.erode(image_bin, horizontalStructure, iterations=1) image_bin = cv2.dilate(image_bin,horizontalStructure, iterations=1) def select_horizontal_lines(image_orig, image_bin): img, contours, hierarchy = cv2.findContours(image_bin.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) region_positions = [] regions_dict = {} for contour in contours: