用python实现图像多边形标注
labelme的Python项目详细描述
标签
用python实现图像多边形标注
说明
labelme是一个图形图像注释工具,灵感来自http://labelme.csail.mit.edu。
它是用python编写的,并使用qt作为图形界面。
VOC数据集实例分割示例。
其他示例(语义分割、bbox检测和分类)。
各种基本体(多边形、矩形、圆、线和点)。
功能
- [X]多边形、矩形、圆、线和点的图像批注。(tutorial)
- [X]用于分类和清理的图像标志注释。(#166)
- [X]视频注释。(video annotation)
- [X]图形用户界面自定义(预定义标签/标志、自动保存、标签验证等)。(#144)
- [X]导出VOC格式数据集以进行语义/实例分割。(semantic segmentation,instance segmentation)
- [X]导出CoCo格式数据集进行实例分割。(instance segmentation)
要求
- ubuntu/macos/windows
- Python2/Python3
- PyQt4 / PyQt5/PySide2
安装
有多种选择:
水蟒
您需要安装Anaconda,然后在下面运行:
# python2 conda create --name=labelme python=2.7 source activate labelme # conda install -c conda-forge pyside2 conda install pyqt pip install labelme # if you'd like to use the latest version. run below:# pip install git+https://github.com/wkentaro/labelme.git# python3 conda create --name=labelme python=3.6 source activate labelme # conda install -c conda-forge pyside2# conda install pyqt# pip install pyqt5 # pyqt5 can be installed via pip on python3 pip install labelme # or you can install everything by conda command# conda install labelme -c conda-forge
Docker
您需要安装docker,然后在下面运行:
wget https://raw.githubusercontent.com/wkentaro/labelme/master/labelme/cli/on_docker.py -O 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 examples/tutorial/apc2016_obj3.jpg -O examples/tutorial/apc2016_obj3.json
./labelme_on_docker examples/semantic_segmentation/data_annotated
ubuntu
# Ubuntu 14.04 / Ubuntu 16.04# Python2# sudo apt-get install python-qt4 # PyQt4 sudo apt-get install python-pyqt5 # PyQt5 sudo pip install labelme # Python3 sudo apt-get install python3-pyqt5 # PyQt5 sudo pip3 install labelme
ubuntu 19.10+/debian(sid)
sudo apt-get install labelme
macos
# macOS Sierra brew install pyqt # maybe pyqt5 pip install labelme # both python2/3 should work# or install standalone executable / app# NOTE: this only installs the `labelme` command brew install wkentaro/labelme/labelme brew cask install wkentaro/labelme/labelme
窗口
首先,按照Anaconda中的说明操作。
# Pillow 5 causes dll load error on Windows.# https://github.com/wkentaro/labelme/pull/174 conda install pillow=4.0.0
用法
运行labelme --help
获取详细信息。
注释保存为JSON文件。
labelme # just open gui# tutorial (single image example)cd examples/tutorial labelme apc2016_obj3.jpg # specify image file labelme apc2016_obj3.jpg -O apc2016_obj3.json # close window after the save labelme apc2016_obj3.jpg --nodata # not include image data but relative image path in JSON file labelme apc2016_obj3.jpg \ --labels highland_6539_self_stick_notes,mead_index_cards,kong_air_dog_squeakair_tennis_ball # specify label list# semantic segmentation examplecd examples/semantic_segmentation labelme data_annotated/ # Open directory to annotate all images in it labelme data_annotated/ --labels labels.txt # specify label list with a file
有关更高级的用法,请参阅示例:
- Tutorial (Single Image Example)
- Semantic Segmentation Example
- Instance Segmentation Example
- Video Annotation Example
命令行参数
--output
指定将向其写入批注的位置。如果该位置以.json结尾,则将向该文件写入一个注释。如果使用.json指定位置,则只能对一个图像进行注释。如果该位置不以.json结尾,程序将假定它是一个目录。批注将存储在此目录中,其名称与在其上生成批注的图像相对应。- 第一次运行labelme时,它将在
~/.labelmerc
中创建一个配置文件。您可以编辑此文件,更改将在下次启动Labelme时应用。如果希望从其他位置使用配置文件,可以使用--config
标志指定该文件。 - 如果没有
--nosortlabels
标志,程序将按字母顺序列出标签。当程序使用此标志运行时,它将按提供的顺序显示标签。 - 标志被分配给整个图像。Example
- 标签被指定给单个多边形。Example
常见问题解答
- 如何将json文件转换为numpy数组?见examples/tutorial。
- 如何加载标签png文件?见examples/tutorial。
- 如何获取语义分段的注释?见examples/semantic_segmentation。
- 如何获取实例分段的注释?见examples/instance_segmentation。
测试
pip install hacking pytest pytest-qt flake8 . pytest -v tests
开发
git clone https://github.com/wkentaro/labelme.git cd labelme # Install anaconda3 and labelme curl -L https://github.com/wkentaro/dotfiles/raw/master/local/bin/install_anaconda3.sh | bash -s . source .anaconda3/bin/activate pip install -e .
如何构建独立的可执行文件
下面介绍如何在MacOS、Linux和Windows上构建独立的可执行文件。
此外,在
the release section。
# Setup conda conda create --name labelme python==3.6.0 conda activate labelme # Build the standalone executable pip install . pip install pyinstaller pyinstaller labelme.spec dist/labelme --version
确认
这个回购协议是mpitid/pylabelme的分叉, 他们的发展已经停止了。
引用此项目
如果您在研究中使用此项目或希望参考自述文件,请使用以下bibtex条目。
@misc{labelme2016, author={Ketaro Wada}, title={{labelme: Image Polygonal Annotation with Python}}, howpublished={\url{https://github.com/wkentaro/labelme}}, year={2016}}