前言
一款用于深度学习图像标注的软件.
一、界面操作演示
二、代码实现
1.准备
你需要如下环境:
Python 3.10
PyQt6 6.4.2
pyqt6-plugins 6.4.2.2.3
PyQt6-Qt6 6.4.3
PyQt6-sip 13.6.0
pyqt6-tools 6.4.2.3.3
python-dotenv 1.0.1
qt6-applications 6.4.3.2.3
qt6-tools 6.4.3.1.3
opencv-python 4.9.0.80
概括来讲就是PyQt全家桶+OpenCV的Python库, 未在低版本测试, 猜测可以在几个小版本的更新前是可以运行的.
2.代码
这里不提供布局代码, 仅提供变量声明以及槽函数.
全局变量
global isDrag # 是否处于标注框的拖拉状态
global penColor # 画笔颜色
global penWidth # 画笔宽度
global startPoint # 标注框起始点
global nowPoint # 标注框被拖拉至的位置
保存标注
def saveAnnotation(self):
# savePath1 = os.path.basename(self.lMessageInPath.toPlainText())
savePath = os.path.basename(self.imagesList[self.imagesListWidget.currentIndex().row()])
savePath = savePath[:-4]
savePath = savePath + ".txt"
savePath = self.outputPath + "/" + savePath
if not os.path.exists(savePath):
file = open(savePath, "w")
file.close()
with open(savePath, "a") as file:
global startPoint
global nowPoint
totalWidth = float(self.lShowImage.width())
totalHeight = float(self.lShowImage.height())
xCenter = abs(float(startPoint.x()) / totalWidth + float(nowPoint.x()) / totalWidth) / 2.0
yCenter = abs(float(startPoint.y()) / totalHeight + float(nowPoint.y()) / totalHeight) / 2.0
xWidth = abs(float(startPoint.x()) / totalWidth - float(nowPoint.x()) / totalWidth)
yWidth = abs(float(startPoint.y()) / totalHeight - float(nowPoint.y()) / totalHeight)
global nowClass
text = nowClass
file.write(