ubuntu中安装labelme

labelme安装过程出现诸多问题,主要还是版本不匹配特别是qt的版本,记录一下安装过程。

labelme安装(conda创建虚拟环境):
1.创建conda环境

conda create --name=labelme python=3.7


2.进入虚拟环境

conda activate labelme


3.安装必要的pyqt5的包,指定5.14.0版本

pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pyqt5==5.14.0


4.安装labelme

pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com labelme


5.labelme(若成功,则会显示图形界面)

  • 14
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Labelme是一个用于图像标注的开源工具,使用Python和Qt开发。下面是一个简单的实现Labelme的代码示例: ```python import os import json from PyQt5.QtCore import Qt, QPoint, QRect from PyQt5.QtGui import QImage, QPixmap, QPainter, QPen from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsScene, QGraphicsView, QGraphicsPixmapItem, QAction, QFileDialog class MainWindow(QMainWindow): def __init__(self): super().__init__() self.image_path = '' self.annotations = [] self.current_annotation = None self.current_polygon = [] self.scene = QGraphicsScene(self) self.view = QGraphicsView(self.scene) self.view.setDragMode(QGraphicsView.ScrollHandDrag) self.view.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(self.view) self.create_actions() self.create_menus() self.setWindowTitle('Labelme') def create_actions(self): self.open_image_action = QAction('Open Image', self) self.open_image_action.setShortcut('Ctrl+O') self.open_image_action.triggered.connect(self.open_image) self.save_annotations_action = QAction('Save Annotations', self) self.save_annotations_action.setShortcut('Ctrl+S') self.save_annotations_action.triggered.connect(self.save_annotations) self.quit_action = QAction('Quit', self) self.quit_action.setShortcut('Ctrl+Q') self.quit_action.triggered.connect(self.close) def create_menus(self): self.file_menu = self.menuBar().addMenu('File') self.file_menu.addAction(self.open_image_action) self.file_menu.addAction(self.save_annotations_action) self.file_menu.addAction(self.quit_action) def open_image(self): options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog file_path, _ = QFileDialog.getOpenFileName(self, 'Open Image', '', 'Images (*.png *.xpm *.jpg *.bmp *.gif)', options=options) if file_path: self.image_path = file_path self.scene.clear() self.current_annotation = None self.current_polygon = [] pixmap = QPixmap(file_path) item = QGraphicsPixmapItem(pixmap) self.scene.addItem(item) self.view.fitInView(item, Qt.KeepAspectRatio) def save_annotations(self): if not self.image_path: return annotations_file = os.path.splitext(self.image_path)[0] + '.json' with open(annotations_file, 'w') as f: json.dump(self.annotations, f) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: if not self.current_annotation: self.current_annotation = { 'image_path': self.image_path, 'annotations': [] } self.annotations.append(self.current_annotation) self.current_polygon.append(self.view.mapToScene(event.pos())) if len(self.current_polygon) > 1: self.scene.addLine(QLineF(self.current_polygon[-2], self.current_polygon[-1]), QPen(Qt.red)) def keyPressEvent(self, event): if event.key() == Qt.Key_Return: if self.current_polygon: self.current_annotation['annotations'].append(self.current_polygon) self.current_polygon = [] self.scene.clear() pixmap = QPixmap(self.image_path) item = QGraphicsPixmapItem(pixmap) self.scene.addItem(item) self.view.fitInView(item, Qt.KeepAspectRatio) if __name__ == '__main__': app = QApplication([]) window = MainWindow() window.show() app.exec_() ``` 这个示例代码实现了打开图片、绘制多边形标注、保存标注等功能。但是这只是一个简单的示例,实际使用还需要考虑更多的细节和功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值