Exemplo n.º 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)
Exemplo n.º 2
0
"""
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)

# for i in range(2,len(results)):