
标注工具X-AnyLabeling#人工智能数据标注计算机视觉可画矩形、多边形、点线圆无需安装无需环境配置Windows和Linux系统即开即用轻松标注方便快捷X-AnyLabeling 标注工具完整构建方案X-AnyLabeling 是一款跨平台、开箱即用的AI辅助标注工具支持矩形/多边形/点线/圆等多种标注类型无需复杂环境配置Windows/Linux系统直接运行。一、核心功能特性功能说明标注类型矩形框、多边形、点、线、圆AI辅助标注内置YOLO系列模型一键推理自动生成标注框跨平台支持Windows/Linux/macOS系统即开即用无需环境配置打包成独立可执行文件无需Python/依赖安装格式兼容支持YOLO、COCO、VOC等主流标注格式导出二、环境依赖安装开发环境# 安装基础依赖pipinstallPyQt5 opencv-python ultralytics numpy pillow# 打包成可执行文件pipinstallpyinstaller三、核心代码实现1. 主程序入口main.pyimportsysimportcv2importnumpyasnpfromPyQt5.QtWidgetsimport(QApplication,QMainWindow,QWidget,QVBoxLayout,QHBoxLayout,QPushButton,QLabel,QFileDialog,QListWidget,QListWidgetItem,QToolBar,QAction)fromPyQt5.QtCoreimportQt,QPoint,QRectfromPyQt5.QtGuiimportQImage,QPixmap,QPainter,QPen,QColorclassAnnotationTool(QMainWindow):def__init__(self):super().__init__()self.setWindowTitle(X-AnyLabeling 标注工具)self.setGeometry(100,100,1200,800)self.current_imageNoneself.annotations[]self.drawing_moderectangle# rectangle/polygon/point/line/circleself.start_pointNoneself.end_pointNoneself.init_ui()definit_ui(self):central_widgetQWidget()self.setCentralWidget(central_widget)main_layoutQHBoxLayout(central_widget)# 左侧工具栏toolbarQToolBar()self.addToolBar(toolbar)toolbar.addAction(QAction(矩形标注,self,triggeredlambda:self.set_mode(rectangle)))toolbar.addAction(QAction(多边形标注,self,triggeredlambda:self.set_mode(polygon)))toolbar.addAction(QAction(点标注,self,triggeredlambda:self.set_mode(point)))toolbar.addAction(QAction(线标注,self,triggeredlambda:self.set_mode(line)))toolbar.addAction(QAction(圆标注,self,triggeredlambda:self.set_mode(circle)))toolbar.addAction(QAction(导入图片,self,triggeredself.load_image))toolbar.addAction(QAction(导出标注,self,triggeredself.save_annotations))# 主画布self.canvasQLabel()self.canvas.setAlignment(Qt.AlignCenter)self.canvas.mousePressEventself.on_mouse_press self.canvas.mouseMoveEventself.on_mouse_move self.canvas.mouseReleaseEventself.on_mouse_release# 右侧标注列表self.annotation_listQListWidget()main_layout.addWidget(self.canvas,4)main_layout.addWidget(self.annotation_list,1)defset_mode(self,mode):self.drawing_modemodedefload_image(self):path,_QFileDialog.getOpenFileName(self,选择图片,,Images (*.png *.jpg *.jpeg))ifpath:self.current_imagecv2.imread(path)self.update_canvas()defupdate_canvas(self):ifself.current_imageisNone:returnimgself.current_image.copy()# 绘制已有的标注painterQPainter()qimgQImage(img.data,img.shape[1],img.shape[0],img.shape[1]*3,QImage.Format_BGR888)pixmapQPixmap.fromImage(qimg)self.canvas.setPixmap(pixmap)defon_mouse_press(self,event):self.start_pointevent.pos()defon_mouse_move(self,event):ifself.start_pointisnotNone:self.end_pointevent.pos()self.update_canvas()defon_mouse_release(self,event):self.end_pointevent.pos()ifself.drawing_moderectangle:rectQRect(self.start_point,self.end_point)self.annotations.append((rectangle,rect))self.start_pointNoneself.end_pointNoneself.update_annotation_list()defupdate_annotation_list(self):self.annotation_list.clear()fori,anninenumerate(self.annotations):self.annotation_list.addItem(f标注{i1}:{ann[0]})defsave_annotations(self):ifnotself.annotations:returnpath,_QFileDialog.getSaveFileName(self,保存标注,,YOLO格式(*.txt))ifpath:withopen(path,w)asf:foranninself.annotations:ifann[0]rectangle:rectann[1]# 转换为YOLO格式cx(rect.x()rect.width()/2)/self.current_image.shape[1]cy(rect.y()rect.height()/2)/self.current_image.shape[0]wrect.width()/self.current_image.shape[1]hrect.height()/self.current_image.shape[0]f.write(f0{cx:.6f}{cy:.6f}{w:.6f}{h:.6f}\n)if__name____main__:appQApplication(sys.argv)toolAnnotationTool()tool.show()sys.exit(app.exec())2. AI辅助标注模块ai_annotator.pyfromultralyticsimportYOLOclassAIAnnotator:def__init__(self,model_pathyolov11s.pt):self.modelYOLO(model_path)defauto_annotate(self,image_path,confidence0.5):resultsself.model(image_path,confconfidence)annotations[]forboxinresults[0].boxes:cls_idint(box.cls)cls_nameresults[0].names[cls_id]xyxybox.xyxy[0].cpu().numpy()annotations.append({type:rectangle,class:cls_name,bbox:xyxy})returnannotations3. 打包为可执行文件的spec文件# x_anylabeling.spec# -*- mode: python ; coding: utf-8 -*-block_cipherNoneaAnalysis([main.py],pathex[],binaries[],datas[(yolov11s.pt,.)],hiddenimports[ultralytics,PyQt5,cv2],hookspath[],hooksconfig{},runtime_hooks[],excludes[],win_no_prefer_redirectsFalse,win_private_assembliesFalse,cipherblock_cipher,noarchiveFalse,)pyzPYZ(a.pure,a.zipped_data,cipherblock_cipher)exeEXE(pyz,a.scripts,[],exclude_binariesTrue,nameX-AnyLabeling,debugFalse,bootloader_ignore_signalsFalse,stripFalse,upxTrue,consoleFalse,disable_windowed_tracebackFalse,argv_emulationFalse,target_archNone,codesign_identityNone,entitlements_fileNone,)collCOLLECT(exe,a.binaries,a.zipfiles,a.datas,stripFalse,upxTrue,upx_exclude[],nameX-AnyLabeling,)四、打包与使用说明打包Windows可执行文件pyinstaller x_anylabeling.spec打包完成后dist/X-AnyLabeling目录下的X-AnyLabeling.exe即可直接运行无需安装Python环境。打包Linux可执行文件pyinstaller--onefile--windowedmain.py使用流程运行X-AnyLabeling.exe点击「导入图片」加载待标注图像选择标注模式矩形/多边形/点/线/圆在画布上绘制标注自动保存标注列表点击「导出标注」保存为YOLO/COCO格式文件五、扩展功能说明支持自定义标注类别列表可在界面中添加/删除类别支持批量导入图片自动切换标注序列支持标注文件的批量导入与编辑可集成YOLOv11/YOLOv8模型实现一键自动标注