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)
Beispiel #2
0
    def select_lines(self):
        image_gray = img_fun.image_gray(self.image)
        image_bin = cv2.adaptiveThreshold(image_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 33, 5)

        horizontalsize = 50
        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_bin = cv2.dilate(image_bin,np.ones((2,500)), iterations=1)
        image_bin = cv2.dilate(image_bin,np.ones((2,200)), iterations=1)


        img,reg,pos = self.select_horizontal_lines(self.image.copy(),image_bin)

        lines,groups = npt.add_additional_lines(pos)

        self.lines = lines
        self.groups = groups

        # cv2.imshow('lines',cv2.resize(image_bin, (1000, 750), interpolation=cv2.INTER_NEAREST))
        # cv2.waitKey(0)
        # cv2.imshow('aaaaaaaaaa',img)

        img_fun.show_image('bin',image_bin)
        img_fun.show_image('img' ,img)
Beispiel #3
0
    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
Beispiel #8
0
    def prepare_image(self):


        self.image_gray = img_fun.image_gray(self.image)

        self.image_bin = cv2.adaptiveThreshold(self.image_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 33, 5)
        image_bin =  self.image_bin

        image_bin = cv2.erode(image_bin,np.ones((3,3)),iterations=1)
        image_bin = cv2.dilate(image_bin,np.ones((3,20)),iterations=1)

        kernel = np.ones((12,12),np.uint8)
        image_bin = cv2.morphologyEx(image_bin, cv2.MORPH_OPEN, kernel)
        image_bin = cv2.erode(image_bin,np.ones((3,30)),iterations=1)


        img_fun.show_image('bars',image_bin)

        self.image_bin = image_bin
        self.select_regions(self.image.copy(),image_bin)
Beispiel #9
0
    def prepare_bar_lines(self):
        image_gray = img_fun.image_gray(self.image.copy())
        image_bin = cv2.adaptiveThreshold(image_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 33, 5)

        image_bin = cv2.erode(image_bin,np.ones((3,3)),iterations=1)
        image_bin = cv2.dilate(image_bin,np.ones((3,20)),iterations=1)

        kernel = np.ones((12,12),np.uint8)
        image_bin = cv2.morphologyEx(image_bin, cv2.MORPH_OPEN, kernel)
        image_bin = cv2.dilate(image_bin,np.ones((20,1)),iterations=1)

        # horizontalsize = 50
        # horizontalStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (1,horizontalsize))
        # image_bin = cv2.erode(image_bin, horizontalStructure, iterations=1)
        # image_bin = cv2.dilate(image_bin,horizontalStructure, iterations=1)

        # cv2.imshow('bar lines',image_bin)
        # cv2.waitKey(0)
        img_fun.show_image('bars',image_bin)
        return image_bin
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
import imageProcessingFunctions as img_fun
import cv2
import numpy as np
import collections

image = img_fun.load_image('images/sheet4.png')
image_gray = img_fun.image_gray(image)
image_bin = img_fun.image_bin(image_gray)
image_bin = img_fun.invert(image_bin)


verticalSize = 3;
verticalStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (verticalSize,1));

image_bin = cv2.erode(image_bin, verticalStructure, iterations=1)

kernel = np.ones((3,3)) # strukturni element 3x3 blok

image_bin = img_fun.dilate(image_bin)
image_bin = img_fun.dilate(image_bin)
image_bin = cv2.dilate(image_bin, kernel, iterations=1)


cv2.imshow('binary', image_bin)
cv2.waitKey(0)



def select_note_heads(image_orig, image_bin):

    img, contours, hierarchy = cv2.findContours(image_bin.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)