Commit 79e90759 authored by SCtom's avatar SCtom

optimize code2

parent a16ee9a8
......@@ -2,6 +2,17 @@ from PyQt5.QtCore import Qt, QDir, QFile, QPoint, QRect, QSize
from PyQt5.QtWidgets import QWidget, QPushButton, QLineEdit, QLabel, QGridLayout
from PyQt5.QtGui import QImage, QImageWriter, QPainter, QPen, qRgb, QPixmap
import os
import matplotlib.pyplot as plt
# Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
from PIL import Image
import numpy as np
import math
from sklearn.metrics import accuracy_score
from sklearn.externals import joblib
class Button(QWidget):
def __init__(self,parent=None, label="Button", on_click=None):
super(Button,self).__init__(parent)
......@@ -67,7 +78,7 @@ class Board(QWidget):
tmpN = int(file[:-4:])
maxf = max(maxf,tmpN)
visibleImage.save('tmp.png')
pixmap = QPixmap('tmp.png').scaled(16,16)
pixmap = QPixmap('tmp.png').scaled(64,64)
pixmap.save(label+'/'+str(max(cnt,maxf)+1)+'.png')
QFile.remove('tmp.png')
......@@ -79,7 +90,7 @@ class Board(QWidget):
QDir().mkdir('Test')
visibleImage.save('tmp.png')
pixmap = QPixmap('tmp.png').scaled(16,16)
pixmap = QPixmap('tmp.png').scaled(64,64)
pixmap.save('Test/temp.png')
QFile.remove('tmp.png')
......@@ -129,3 +140,46 @@ class Board(QWidget):
painter = QPainter(newImage)
painter.drawImage(QPoint(0,0), image)
self.image = newImage
def data_prep_test(self):
im = Image.open('Test/temp.png')
iar = np.array(im)
width, height = im.size
test_data = np.zeros(width*height)
test_data = np.zeros(64*64)
count = 0
for i in range(len(iar)):
for j in range(len(iar[i])):
test_data[count] = math.floor(((np.sum(iar[i][j][:3]/765))))
#print(test_data[count])
count+=1
return test_data
def data_prep_train(self):
print('preporcessing..')
folder_name = 'Image/'
list_of_label = os.listdir(folder_name)
digit_data = list()
digit_label = list()
for label in list_of_label:
label_path = folder_name+str(label)+'/'
list_of_data = os.listdir(label_path)
#print(list_of_data)
for data in list_of_data:
im = Image.open(label_path+'/'+data)
arr_im = np.array(im)
width, height = im.size
gen_data = np.zeros(width*height)
count = 0
for i in range(len(arr_im)):
for j in range(len(arr_im[i])):
#ทำ Normalize ด้วยการ (R+G+B) หาร 765 มาจาก (255+255+255)
gen_data[count] = math.floor(((np.sum(arr_im[i][j][:3]/765))))
count+=1
digit_data.append( gen_data )
digit_label.append( label )
digit_data = np.array(digit_data) #ข้อมูล
digit_label = np.array(digit_label) # label ของข้อมูล
return digit_data,digit_label
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment