Exemple #1
0
    def predict_ann(self):
        filename = tkFileDialog.askopenfilename(initialdir='images/')
        image = cv2.imread(filename)
        if image is None:
            return

        image_bin = self.prepare_image(image)
        groups = self.get_groups(image)

        image_orig,selected_regions, positions,reg_details = imgFunctions.select_roi(image.copy(), image_bin, groups)

        self.inputs = ann_fun.prepare_for_ann(selected_regions)
        self.outputs = ann_fun.convert_output(self.alphabet)


        self.sheet = np_fun.get_notes(image)


        with open('saved_ann/trained_ann.pkl', 'rb') as input:
            self.ann = pickle.load(input)

        results = self.ann.predict(np.array(self.inputs, np.float32))
        print 'results = ',results
        results = ann_fun.display_result(results, self.alphabet)
        results = self.replace_beams(results)
        print results

        self.chords = self.sheet.set_chords_duration(results[2:])

        tkMessageBox.showinfo("Done", "Sheet loaded. Click on Play Sheet button.")

        img_fun.show_image('Sheet',image)
Exemple #2
0
    def train_ann(self):



        image = cv2.imread("images/train.png")
        image_bin = self.prepare_image(image)
        groups = self.get_groups(image)
        image_orig,selected_regions, positions,reg_details = imgFunctions.select_roi(image.copy(), image_bin,groups)

        # cv2.imshow('bin',image_bin)
        # cv2.waitKey(0)
        #
        # cv2.imshow('bin',image_orig)
        # cv2.waitKey(0)


        inputs = ann_fun.prepare_for_ann(selected_regions)
        outputs = ann_fun.convert_output(self.alphabet)

        # notes = np_fun.get_notes(image)

        self.ann = ann_fun.create_ann(len(self.alphabet))
        self.ann = ann_fun.train_ann(self.ann, inputs, outputs)


        saver = se.Serialize('trained_ann.pkl',self.ann)
        saver.save()

        results = self.ann.predict(np.array(inputs, np.float32))

        results = ann_fun.display_result(results, self.alphabet)


        self.progressbar.stop()
        self.label["text"] = "Done"
        self.label["foreground"] = '#437C17'




        tkMessageBox.showinfo("Info", "Done!")
Exemple #3
0
def play(ann,notes,inputs,outputs,alphabet,sound_font):

    results = ann.predict(np.array(inputs, np.float32))
    res = ann_fun.display_result(results,alphabet)
    res = replace_beams(res)

    print len(res)
    print len(notes)

    notes_with_rests = []

    note_cnt = 0
    for i in range(2, len(res)):
        symbol = str(res[i])

        if(symbol.startswith('rest')):
            rest = nt.Note(symbol)
            dur = symbol.split('-')[1]
            rest.set_duration(1/int(dur))
            notes_with_rests.append(rest)
        else:
            note = notes[note_cnt]
            note.set_duration(1/int(res[i]))
            notes_with_rests.append(note)
            note_cnt+=1

    for i in range(len(notes_with_rests)):
        notes_with_rests[i].print_note()

    '''
    for i in range(len(notes)):
        notes[i].print_note()
        sgen.playNote(notes[i].frequency, notes[i].duration)
    '''

    #play_notes.playNotes(notes_with_rests)
    play_notes_fsynth.play_notes(notes_with_rests,sound_font)