代码拉取完成,页面将自动刷新
同步操作将从 陈京/YOLO-Animal-Recognition-System-Code-Tutorial 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
class Thread_1(QThread): # 线程1
def __init__(self,info1):
super().__init__()
self.info1=info1
self.run2(self.info1)
def run2(self, info1):
result = []
result = det_yolov7(info1)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1280, 960)
MainWindow.setStyleSheet("background-image: url(\"./template/carui.png\")")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(168, 60, 551, 71))
self.label.setAutoFillBackground(False)
self.label.setStyleSheet("")
self.label.setFrameShadow(QtWidgets.QFrame.Plain)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.label.setStyleSheet("font-size:42px;font-weight:bold;font-family:SimHei;background:rgba(255,255,255,0);")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(40, 188, 751, 501))
self.label_2.setStyleSheet("background:rgba(255,255,255,1);")
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(73, 746, 851, 174))
self.textBrowser.setStyleSheet("background:rgba(0,0,0,0);")
self.textBrowser.setObjectName("textBrowser")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(1020, 750, 150, 40))
self.pushButton.setStyleSheet("background:rgba(53,142,255,1);border-radius:10px;padding:2px 4px;")
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(1020, 810, 150, 40))
self.pushButton_2.setStyleSheet("background:rgba(53,142,255,1);border-radius:10px;padding:2px 4px;")
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(1020, 870, 150, 40))
self.pushButton_3.setStyleSheet("background:rgba(53,142,255,1);border-radius:10px;padding:2px 4px;")
self.pushButton_3.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "基于YOLOv7动物识别系统"))
self.label.setText(_translate("MainWindow", "基于YOLOv7动物识别系统"))
self.label_2.setText(_translate("MainWindow", "请添加对象,注意路径不要存在中文"))
self.pushButton.setText(_translate("MainWindow", "选择对象"))
self.pushButton_2.setText(_translate("MainWindow", "开始识别"))
self.pushButton_3.setText(_translate("MainWindow", "退出系统"))
# 点击文本框绑定槽事件
self.pushButton.clicked.connect(self.openfile)
self.pushButton_2.clicked.connect(self.click_1)
self.pushButton_3.clicked.connect(self.handleCalc3)
def openfile(self):
global sname, filepath
fname = QFileDialog()
fname.setAcceptMode(QFileDialog.AcceptOpen)
fname, _ = fname.getOpenFileName()
if fname == '':
return
filepath = os.path.normpath(fname)
sname = filepath.split(os.sep)
ui.printf("当前选择的文件路径是:%s" % filepath)
try:
show = cv2.imread(filepath)
ui.showimg(show)
except:
ui.printf('请检查路径是否存在中文,更名后重试!')
def handleCalc3(self):
os._exit(0)
def printf(self,text):
self.textBrowser.append(text)
self.cursor = self.textBrowser.textCursor()
self.textBrowser.moveCursor(self.cursor.End)
QtWidgets.QApplication.processEvents()
def showimg(self,img):
global vid
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
_image = QtGui.QImage(img2[:], img2.shape[1], img2.shape[0], img2.shape[1] * 3,
QtGui.QImage.Format_RGB888)
n_width = _image.width()
n_height = _image.height()
if n_width / 500 >= n_height / 400:
ratio = n_width / 700
else:
ratio = n_height / 700
new_width = int(n_width / ratio)
new_height = int(n_height / ratio)
new_img = _image.scaled(new_width, new_height, Qt.KeepAspectRatio)
self.label_2.setPixmap(QPixmap.fromImage(new_img))
def click_1(self):
global filepath
try:
self.thread_1.quit()
except:
pass
self.thread_1 = Thread_1(filepath) # 创建线程
self.thread_1.wait()
self.thread_1.start() # 开始线程
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。