python图像标记工具怎么用_labelme:用Python实现的图像可视化标记工具

icon.png?raw=true

labelme: Image Annotation Tool with Python

68747470733a2f2f696d672e736869656c64732e696f2f707970692f762f6c6162656c6d652e73766768747470733a2f2f7472617669732d63692e6f72672f776b656e7461726f2f6c6162656c6d652e7376673f6272616e63683d6d617374657268747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f657078663962366334376377333733792f6272616e63682f6d61737465723f7376673d7472756568747470733a2f2f696d672e736869656c64732e696f2f646f636b65722f6275696c642f776b656e7461726f2f6c6162656c6d652e737667

Labelme is a graphical image annotation tool inspired by http://labelme.csail.mit.edu.

It is written in Python and uses Qt for its graphical interface.

Requirements

Ubuntu / macOS / Windows

Python2 / Python3

Installation

There are options:

Platform agonistic installation: Anaconda, Docker

Platform specific installation: Ubuntu, macOS

Anaconda

You need install Anaconda, then run below:

conda create --name=labelme python=2.7

source activate labelme

conda install pyqt

pip install labelme

Docker

You need install docker, then run below:

wget https://raw.githubusercontent.com/wkentaro/labelme/master/scripts/labelme_on_docker

chmod u+x labelme_on_docker

# Maybe you need http://sourabhbajaj.com/blog/2017/02/07/gui-applications-docker-mac/ on macOS

./labelme_on_docker static/apc2016_obj3.jpg -O static/apc2016_obj3.json

Ubuntu

sudo apt-get install python-qt4 pyqt4-dev-tools

sudo pip install labelme

macOS

brew install qt qt4 || brew install pyqt # qt4 is deprecated

pip install labelme

Usage

Annotation

Run labelme --help for detail.

labelme # Open GUI

labelme static/apc2016_obj3.jpg # Specify file

labelme static/apc2016_obj3.jpg -O static/apc2016_obj3.json # Close window after the save

The annotations are saved as a JSON file. The file includes the image itself.

Visualization

To view the json file quickly, you can use utility script:

labelme_draw_json static/apc2016_obj3.json

Convert to Dataset

To convert the json to set of image and label, you can run following:

labelme_json_to_dataset static/apc2016_obj3.json

Sample

Screencast

screencast.gif

Acknowledgement

This repo is the fork of mpitid/pylabelme, whose development is currently stopped.

要批量可视化 LabelMe 的 JSON 标注文件,你可以按照以下步骤进行操作: 1. 确保你已经安装了 labelme 包。你可以使用以下命令来安装: ``` pip install labelme ``` 2. 创建一个 Python 脚本,导入所需的库: ```python import os import cv2 import labelme import numpy as np ``` 3. 指定包含 JSON 文件的目录路径: ```python json_dir = 'path/to/your/json/files' ``` 4. 遍历 JSON 文件目录中的每个文件,加载 JSON 数据并可视化: ```python for json_file in os.listdir(json_dir): if json_file.endswith('.json'): json_path = os.path.join(json_dir, json_file) label_data = labelme.LabelFile(json_path) image_data = label_data.imageData annotations = label_data.shapes image = np.frombuffer(image_data, dtype=np.uint8) image = cv2.imdecode(image, cv2.IMREAD_COLOR) for annotation in annotations: shape_type = annotation['shape_type'] points = annotation['points'] if shape_type == 'rectangle': x, y, w, h = cv2.boundingRect(np.array(points)) cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2) elif shape_type == 'polygon': pts = np.array(points, np.int32) cv2.polylines(image, [pts], True, (0, 255, 0), 2) cv2.imshow("Annotated Image", image) cv2.waitKey(0) cv2.destroyAllWindows() ``` 通过以上步骤,你可以批量读取 LabelMe 的 JSON 标注文件,并将其中的图像和标注信息可视化显示出来。请确保已正确安装所需的包,并将代码中的文件路径替换为实际的 JSON 文件目录路径。注意,该代码会逐个显示每张图像可视化结果,按任意键继续到下一张图像。如果你希望自动化处理所有图像,可以相应地修改代码逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值