Commit 60a005fc authored by Wichit Sombat's avatar Wichit Sombat

latest download from google team drive

parent 26b1f239
csubupromote@gmail.com
123456789Az
\ No newline at end of file
from PyQt5.QtCore import QDir, QFile, QPoint, QRect, QSize, Qt
from PyQt5.QtGui import QImage, QImageWriter, QPainter, QPen, qRgb, QPixmap
from PyQt5.QtWidgets import (QAction, QApplication, QColorDialog, QFileDialog,
QInputDialog, QMainWindow, QMenu, QMessageBox, QWidget)
class Board(QWidget):
def __init__(self,parent=None):
super(Board,self).__init__(parent)
self.setAttribute(Qt.WA_StaticContents)
self.penWidth = 50
self.writing = False
self.penColor = Qt.black
self.image = QImage()
self.lastPoint = QPoint()
self.setFixedSize(512,512)
def saveImage(self,label):
import os
visibleImage = self.image
self.resizeImage(visibleImage,self.size())
if QDir('Image').exists() == False:
QDir().mkdir('Image')
label = 'Image/'+label
if QDir(label).exists() == False:
QDir().mkdir(label)
cnt = 0
maxf = 0
for file in os.listdir(label):
if file.endswith('.bmp'):
cnt += 1
tmpN = int(file[:-4:])
maxf = max(maxf,tmpN)
visibleImage.save('tmp.bmp')
pixmap = QPixmap('tmp.bmp').scaled(8,8)
pixmap.save(label+'/'+str(max(cnt,maxf)+1)+'.bmp')
QFile.remove('tmp.bmp')
def paintEvent(self, event):
painter = QPainter(self)
dirtyRect = event.rect()
painter.drawImage(dirtyRect, self.image, dirtyRect)
def clearImage(self):
self.image.fill(qRgb(255,255,255))
self.update()
def mousePressEvent(self,event):
if event.button() == Qt.LeftButton:
self.lastPoint = event.pos()
self.writing = True
def mouseMoveEvent(self,event):
if (event.buttons() & Qt.LeftButton) and self.writing:
self.drawLineTo(event.pos())
def mouseReleaseEvent(self,event):
if event.button() == Qt.LeftButton and self.writing:
self.drawLineTo(event.pos())
self.writing = False
def resizeEvent(self,event):
self.resizeImage(self.image,self.size())
self.update()
super(Board,self).resizeEvent(event)
def drawLineTo(self, endPoint):
painter = QPainter(self.image)
painter.setPen(QPen(self.penColor, self.penWidth, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
painter.drawLine(self.lastPoint, endPoint)
self.writing = True
rad = self.penWidth/2 + 2
self.update(QRect(self.lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad))
self.lastPoint = QPoint(endPoint)
def resizeImage(self,image, newSize):
if image.size() == newSize:
return
newImage = QImage(newSize, QImage.Format_RGB32)
newImage.fill(qRgb(255,255,255))
painter = QPainter(newImage)
painter.drawImage(QPoint(0,0), image)
self.image = newImage
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QPushButton, QGridLayout
class ClearButton(QWidget):
def __init__(self,parent=None):
super(ClearButton,self).__init__(parent)
self.initUI()
def initUI(self):
button = QPushButton("Clear Image", self)
button.move(220,0)
button.clicked.connect(self.on_click)
grid = QGridLayout()
grid.addWidget(button,1,0,1,2)
self.setLayout(grid)
def on_click(self):
parent = self.parent()
parent.scribbleArea.clearImage()
\ No newline at end of file
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QPushButton, QLineEdit, QLabel, QGridLayout
class TestWidget(QWidget):
def __init__(self,parent=None):
super(TestWidget,self).__init__(parent)
self.initUI()
def initUI(self):
button = QPushButton("Test", self)
lbl = QLabel(self)
lbl.setText('Results :')
self.qle = QLineEdit(self)
self.qle.setReadOnly(True)
button.clicked.connect(self.on_click)
grid = QGridLayout()
grid.addWidget(lbl,1,0)
grid.addWidget(self.qle,1,1)
grid.addWidget(button,1,2)
self.setLayout(grid)
def on_click(self):
parent = self.parent()
parent.scribbleArea.clearImage()
\ No newline at end of file
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QPushButton, QLineEdit, QLabel, QGridLayout
class TrainWidget(QWidget):
def __init__(self,parent=None):
super(TrainWidget,self).__init__(parent)
self.initUI()
def initUI(self):
lbl = QLabel(self)
lbl.setText('Label : ')
self.qle = QLineEdit(self)
button = QPushButton("Save", self)
button.clicked.connect(self.on_click)
grid = QGridLayout()
grid.addWidget(lbl,1,0)
grid.addWidget(self.qle,1,1)
grid.addWidget(button,1,2)
self.setLayout(grid)
def on_click(self):
parent = self.parent()
parent.scribbleArea.saveImage(self.qle.text())
parent.scribbleArea.clearImage()
\ No newline at end of file
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QAction, QApplication, QWidget,QGridLayout)
from board import Board
from clearButton import ClearButton
from trainWidget import TrainWidget
from testWidget import TestWidget
class MainWindow(QWidget):
def __init__(self,parent=None):
super(MainWindow, self).__init__(parent)
self.scribbleArea = Board()
self.button = ClearButton()
self.train = TrainWidget()
self.test = TestWidget()
grid = QGridLayout()
grid.addWidget(self.scribbleArea,1,0)
grid.addWidget(self.button,2,0)
grid.addWidget(self.train,3,0)
grid.addWidget(self.test,4,0)
self.setLayout(grid)
self.setWindowTitle("number ubu")
self.resize(512, 650)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
import sys
import time
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QGraphicsView, QGraphicsScene,QPushButton, QVBoxLayout, QGraphicsLineItem
from PyQt5.QtGui import QPainter, QColor, QFont, QPen
from PyQt5.QtCore import Qt, QRectF, QPointF, QLineF
class Window(QWidget):
def __init__(self):
super().__init__()
self.View = ViewDT(self)
self.button = QPushButton('Clear', self)
self.button.clicked.connect(self.handleClearView)
layout = QVBoxLayout(self)
layout.addWidget(self.View)
layout.addWidget(self.button)
def handleClearView(self):
self.View.scene().clear()
class ViewDT(QGraphicsView):
def __init__(self,parent):
QGraphicsView.__init__(self,parent)
self.setScene(QGraphicsScene(self))
self.setSceneRect(QRectF(self.viewport().rect()))
self.test = False
self.start = 0
self.end = 0
def mousePressEvent(self,event):
self.test = True
self.__start = event.pos()
self.start = QPointF(self.mapToScene(event.pos()))
def mouseMoveEvent(self,event):
self.end = QPointF(self.mapToScene(event.pos()))
if self.start != self.end and self.test is True:
self.scene().addItem(QGraphicsLineItem(QLineF(self.start,self.end)))
self.start = self.end
def mouseReleaseEvent(self, event):
self.test = False
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.resize(640, 480)
window.show()
sys.exit(app.exec_())
\ No newline at end of file
This diff is collapsed.
......@@ -2,19 +2,19 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"SVC(C=0.1, cache_size=200, class_weight=None, coef0=0.0,\n",
" decision_function_shape='ovr', degree=3, gamma=0.001, kernel='rbf',\n",
" decision_function_shape=None, degree=3, gamma=0.001, kernel='rbf',\n",
" max_iter=-1, probability=False, random_state=None, shrinking=True,\n",
" tol=0.001, verbose=False)"
]
},
"execution_count": 1,
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
......@@ -64,7 +64,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 42,
"metadata": {},
"outputs": [
{
......@@ -76,7 +76,7 @@
" 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9])"
]
},
"execution_count": 2,
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
......@@ -87,10 +87,8 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"execution_count": 84,
"metadata": {},
"outputs": [],
"source": [
"#การทดสอบ\n",
......@@ -111,7 +109,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 85,
"metadata": {},
"outputs": [
{
......@@ -120,7 +118,7 @@
"array([7])"
]
},
"execution_count": 4,
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
......@@ -132,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 91,
"metadata": {},
"outputs": [
{
......@@ -140,7 +138,7 @@
"output_type": "stream",
"text": [
"Classification report for classifier SVC(C=0.1, cache_size=200, class_weight=None, coef0=0.0,\n",
" decision_function_shape='ovr', degree=3, gamma=0.001, kernel='rbf',\n",
" decision_function_shape=None, degree=3, gamma=0.001, kernel='rbf',\n",
" max_iter=-1, probability=False, random_state=None, shrinking=True,\n",
" tol=0.001, verbose=False):\n",
" precision recall f1-score support\n",
......@@ -188,7 +186,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 70,
"metadata": {},
"outputs": [
{
......@@ -196,10 +194,10 @@
"output_type": "stream",
"text": [
"Fitting the classifier to the training set\n",
"done in 0.436s\n",
"done in 0.234s\n",
"Best estimator found by grid search:\n",
"SVC(C=1000.0, cache_size=200, class_weight='balanced', coef0=0.0,\n",
" decision_function_shape='ovr', degree=3, gamma=0.0005, kernel='rbf',\n",
" decision_function_shape=None, degree=3, gamma=0.0005, kernel='rbf',\n",
" max_iter=-1, probability=False, random_state=None, shrinking=True,\n",
" tol=0.001, verbose=False)\n"
]
......@@ -250,7 +248,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.1"
}
},
"nbformat": 4,
......
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