示例#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)
示例#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!")
示例#3
0
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)

alphabet = ["g-key", "time-sig-4/4", "1", "2", "4", "8"]
inputs = ann_fun.prepare_for_ann(selected_regions)
outputs = ann_fun.convert_output(alphabet)

notes = np_fun.get_notes(image)
"""
for i in range(len(notes)):
    notes[i].print_note()
    sgen.playNote(notes[i].frequency, notes[i].duration)
"""
# ann = ann_fun.create_ann()
# ann = ann_fun.train_ann(ann, inputs, outputs)

print "done"

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

# results = ann_fun.display_result(results,alphabet)