def batchConvertToBoundaries(self): overwriteAll = False annotation = Annotation() worker = ConvertToBoundariesWorker() # Convert each image for idx, filename in enumerate(self.imageList): if (self.canceled): break # get label json file name imageExt = os.path.splitext(filename)[1] gtfilename = filename.replace(imageExt, self.gtExt) filename = os.path.join(self.imageDir, gtfilename) filename = os.path.normpath(filename) # Update progress dialog self.updateProgress.emit(idx + 1, "Converting {0}".format(gtfilename)) # Check if label json file exist if (not os.path.isfile(filename)): text = "{0} not exist. Continue?".format(filename) self.mutex.lock() self.information.emit("IOError", text) self.waitCondition.wait(self.mutex) self.mutex.unlock() if (self.userOperationResult == QtGui.QMessageBox.Yes): continue else: break try: annotation = Annotation() annotation.fromJsonFile(filename) except StandardError as e: text = "Error parsing labels in {0}. \nContinue?".format( filename) self.mutex.lock() self.information.emit("IOError", text) self.waitCondition.wait(self.mutex) self.mutex.unlock() if (self.userOperationResult == QtGui.QMessageBox.Yes): continue else: break # Skip all image of has no instance labels if (not annotation.objects): continue # Check if it has occlusion boundary label if (not overwriteAll and annotation.boundaries): text = "{0} already exists occlusion boundary labels. Do you want to overwrite?".format( filename) self.mutex.lock() self.information.emit("Overwrite", text) self.waitCondition.wait(self.mutex) self.mutex.unlock() if (self.userOperationResult == QtGui.QMessageBox.No): continue elif (self.userOperationResult == QtGui.QMessageBox.YesToAll): overwriteAll = True height = annotation.imgHeight width = annotation.imgWidth worker.setObjects(annotation.objects) worker.setSegmentMap(height, width) polygon = worker.convertToBoundaries() # Create a new boundary object boundaries = AnnBoundary() boundaries.polygon = polygon boundaries.deleted = 0 boundaries.verified = 0 boundaries.user = getpass.getuser() boundaries.updateDate() annotation.boundaries = boundaries try: annotation.toJsonFile(filename) except StandardError as e: text = "Error writting labels to {0}. \nContinue?".format( filename) self.mutex.lock() self.information.emit("IOError", text) self.waitCondition.wait(self.mutex) self.mutex.unlock() if (self.userOperationResult == QtGui.QMessageBox.Yes): continue else: break self.finished.emit()