第一版,实现对图片的标注,无法画框等
# -*- coding: utf-8 -*-
import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPainter, QPixmap
from PyQt5.QtCore import Qt, QPoint
from PyQt5 import QtWidgets, QtGui
class MWindow(QWidget):
def __init__(self):
super(MWindow, self).__init__()
self.pic_path_list = []
self.label = QLabel(self)
self.img_index = 0
self.initUi()
self.open_path=''
def initUi(self):
# 设置窗口大小及标题
self.resize(800, 800)
self.setWindowTitle("染色体标注")
# 设置标签
# 设置label
self.label.setText("显示图片的区域在这里")
self.label.setFixedSize(600, 400)
self.label.move(0, 100)
# 设置文件导入菜单栏
# 添加菜单按钮
btn_menu = QPushButton(self)
btn_menu.setParent(self)
btn_menu.setText("菜单")
# 导入菜单
menu = QMenu(self)
# 添加菜单栏选项
file_open = QAction(self)
file_open.setText("打开文件夹")
soft_exit = QAction(self)
soft_exit.setText("退出")
menu.addAction(file_open)
menu.addAction(soft_exit)
btn_menu.setMenu(menu)
# 打开文件夹并导入文件
file_open.triggered.connect(self.opendir)
#设置上一张下一张按钮
#添加上一张下一张按钮
btn_last = QPushButton(self)
btn_next = QPushButton(self)
btn_last.setText("上一张")
btn_last.move(200,550)
btn_next.setText("下一张")
btn_next.move(300, 550)
#绑定事件
btn_last.clicked.connect(self.show_last_img)
btn_next.clicked.connect(self.show_next_img)
#添加正常异常按钮
btn_norm_choose = QPushButton(self)
btn_abnorm_choose = QPushButton(self)
btn_norm_choose.setText("正常")
btn_norm_choose.move(650, 200)
btn_abnorm_choose.setText("异常")
btn_abnorm_choose.move(650, 300)
# 绑定事件
btn_last.clicked.connect(self.show_last_img)
btn_next.clicked.connect(self.show_next_img)
btn_norm_choose.clicked.connect(self.writeNorm)
btn_abnorm_choose.clicked.connect(self.writeAbnorm)
# 进行文件导入的方法
def opendir(self):
file_path = QFileDialog.getExistingDirectory(self, "请选择您要标注的图片所在文件夹", "./")
self.open_path=file_path
print(file_path