roLabelImg是基于labelImg改进的,也是用来标注为VOC格式的数据,但是在labelImg的基础上增加了能够使标注的框进行旋转的功能。
网址:https://github.com/cgvict/roLabelImg/blob/master/README.rst
详细可以参考labelImg里的说明(https://github.com/tzutalin/labelImg)
1) 下载Anaconda(python3+)
2)打开命令窗口,输入如下命令
$ conda install pyqt=5
$ pyrcc5 -o libs/resources.py resources.qrc
$ python labelImg.py , 或
$ python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
3) 编译打包,可以使用如下命令:
$ /PATH/TO/pyinstaller.exe --hidden-import=xml ^
--hidden-import=xml.etree ^
--hidden-import=xml.etree.ElementTree ^
--hidden-import=lxml.etree ^
-D -F -n roLabelImg -c "../labelImg.py" -p ../libs -p ../
软件快捷键如下:
1) w: 创建水平矩形目标框
2) e: 创建旋转矩形目标框
3) zxcv: 旋转目标框,键z和建x是逆时针旋转,键c和键v是顺时针旋转
使用roLabelImg标注得到的目标框的信息如下:
def rotatePoint(xc,yc, xp,yp, theta):
xoff = xp-xc;
yoff = yp-yc;
cosTheta = math.cos(theta)
sinTheta = math.sin(theta)
pResx = cosTheta * xoff + sinTheta * yoff
pResy = - sinTheta * xoff + cosTheta * yoff
# pRes = (xc + pResx, yc + pResy)
return xc+pResx,yc+pResy
def addRotatedShape(cx,cy,w,h,angle):
p0x,p0y = self.rotatePoint(cx,cy, cx - w/2, cy - h/2, -angle)
p1x,p1y = self.rotatePoint(cx,cy, cx + w/2, cy - h/2, -angle)
p2x,p2y = self.rotatePoint(cx,cy, cx + w/2, cy + h/2, -angle)
p3x,p3y = self.rotatePoint(cx,cy, cx - w/2, cy + h/2, -angle)
points = [(p0x, p0y), (p1x, p1y), (p2x, p2y), (p3x, p3y)]
return points
详细代码参考: pascal_voc_io.py(https://github.com/cgvict/roLabelImg/blob/master/libs/pascal_voc_io.py)