Implement verified feature

When pressing space, the user can flag the image as verified, a green background will appear.
This is used when creating a dataset automatically, the user can then through all the pictures and flag them instead of annotate them.
This commit is contained in:
Thibaut Mattio
2017-03-08 11:01:36 +08:00
parent ce853362e5
commit 3abd685a8d
4 changed files with 62 additions and 15 deletions
+13 -2
View File
@@ -59,6 +59,7 @@ class Canvas(QWidget):
# Set widget options.
self.setMouseTracking(True)
self.setFocusPolicy(Qt.WheelFocus)
self.verified = False
def enterEvent(self, ev):
self.overrideCursor(self._cursor)
@@ -184,7 +185,7 @@ class Canvas(QWidget):
if ev.button() == Qt.LeftButton:
if self.drawing():
self.handleDrawing(pos)
self.handleDrawing(pos)
else:
self.selectShapePoint(pos)
self.prevPoint = pos
@@ -208,7 +209,7 @@ class Canvas(QWidget):
elif ev.button() == Qt.LeftButton:
pos = self.transformPos(ev.pos())
if self.drawing():
self.handleDrawing(pos)
self.handleDrawing(pos)
def endMove(self, copy=False):
assert self.selectedShape and self.selectedShapeCopy
@@ -419,6 +420,16 @@ class Canvas(QWidget):
p.setBrush(brush)
p.drawRect(leftTop.x(), leftTop.y(), rectWidth, rectHeight)
self.setAutoFillBackground(True)
if self.verified:
pal = self.palette()
pal.setColor(self.backgroundRole(), QColor(184, 239, 38, 128))
self.setPalette(pal)
else:
pal = self.palette()
pal.setColor(self.backgroundRole(), QColor(232, 232, 232, 255))
self.setPalette(pal)
p.end()
def transformPos(self, point):
+8 -4
View File
@@ -24,8 +24,7 @@ class LabelFile(object):
self.shapes = ()
self.imagePath = None
self.imageData = None
if filename is not None:
self.load(filename)
self.verified = False
def savePascalVocFormat(self, filename, shapes, imagePath, imageData,
lineColor=None, fillColor=None, databaseSrc=None):
@@ -41,6 +40,8 @@ class LabelFile(object):
1 if image.isGrayscale() else 3]
writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt,
imageShape, localImgPath=imagePath)
writer.verified = self.verified
for shape in shapes:
points = shape['points']
label = shape['label']
@@ -50,6 +51,9 @@ class LabelFile(object):
writer.save(targetFile=filename)
return
def toggleVerify(self):
self.verified = not self.verified
@staticmethod
def isLabelFile(filename):
fileSuffix = os.path.splitext(filename)[1].lower()
@@ -72,10 +76,10 @@ class LabelFile(object):
# Martin Kersner, 2015/11/12
# 0-valued coordinates of BB caused an error while
# training faster-rcnn object detector.
if (xmin < 1):
if xmin < 1:
xmin = 1
if (ymin < 1):
if ymin < 1:
ymin = 1
return (int(xmin), int(ymin), int(xmax), int(ymax))
+10
View File
@@ -19,6 +19,7 @@ class PascalVocWriter:
self.imgSize = imgSize
self.boxlist = []
self.localImgPath = localImgPath
self.verified = False
def prettify(self, elem):
"""
@@ -39,6 +40,8 @@ class PascalVocWriter:
return None
top = Element('annotation')
top.set('verified', 'yes' if self.verified else 'no')
folder = SubElement(top, 'folder')
folder.text = self.foldername
@@ -119,6 +122,7 @@ class PascalVocReader:
# [labbel, [(x1,y1), (x2,y2), (x3,y3), (x4,y4)], color, color]
self.shapes = []
self.filepath = filepath
self.verified = False
self.parseXML()
def getShapes(self):
@@ -137,6 +141,12 @@ class PascalVocReader:
parser = etree.XMLParser(encoding='utf-8')
xmltree = ElementTree.parse(self.filepath, parser=parser).getroot()
filename = xmltree.find('filename').text
try:
verified = xmltree.attrib['verified']
if verified == 'yes':
self.verified = True
except AttributeError:
self.verified = False
for object_iter in xmltree.findall('object'):
bndbox = object_iter.find("bndbox")