-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeshihha.py
71 lines (63 loc) · 2.68 KB
/
keshihha.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test2.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow,QFileDialog
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import os
import joblib
import svm
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(645, 475)
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(230, 340, 141, 41))
self.pushButton.setAutoDefault(False)
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(220, 50, 191, 221))
self.label.setWordWrap(False)
self.label.setObjectName("label")
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setGeometry(QtCore.QRect(220, 280, 191, 41))
self.textEdit.setObjectName("textEdit")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "手写体识别"))
self.pushButton.setText(_translate("Dialog", "打开图片"))
self.label.setText(_translate("Dialog", "显示图片"))
class MyWindow(QMainWindow, Ui_Dialog):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.openImage)
def openImage(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "../data/Mnist-image/test")
png = QtGui.QPixmap(imgName).scaled(self.label.width(), self.label.height())
self.label.setPixmap(png)
self.textEdit.setText(imgName)
path = sys.path[1]
model_path = os.path.join(path, r'模型地址\svm.model')
clf = joblib.load(model_path)
dataMat=svm.img2vector(imgName)
preResult = clf.predict(dataMat)
self.textEdit.setReadOnly(True)
self.textEdit.setStyleSheet("color:red")
self.textEdit.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
self.textEdit.setFontPointSize(9)
self.textEdit.setText("预测的结果是:")
self.textEdit.append(preResult[0])
if __name__ == '__main__':
app = QApplication(sys.argv)
myWin = MyWindow()
myWin.show()
sys.exit(app.exec_())