def savePascalVocFormat(self, filename, shapes, imagePath, imageData, lineColor=None, fillColor=None, databaseSrc=None): imgFolderPath = os.path.dirname(imagePath) imgFolderName = os.path.split(imgFolderPath)[-1] imgFileName = os.path.basename(imagePath) imgFileNameWithoutExt = os.path.splitext(imgFileName)[0] # Read from file path because self.imageData might be empty if saving to # Pascal format image = QImage() image.load(imagePath) imageShape = [ image.height(), image.width(), 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'] # Add Chris difficult = int(shape['difficult']) direction = shape['direction'] isRotated = shape['isRotated'] # if shape is normal box, save as bounding box # print('direction is %lf' % direction) if not isRotated: bndbox = LabelFile.convertPoints2BndBox(points) writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, difficult) else: #if shape is rotated box, save as rotated bounding box robndbox = LabelFile.convertPoints2RotatedBndBox(shape) ''' writer.addRotatedBndBox(robndbox[0],robndbox[1], robndbox[2],robndbox[3],robndbox[4],label,difficult) ''' # CC Wang 2019/10/17 writer.addRotatedBndBox(robndbox[0], robndbox[1], robndbox[2], robndbox[3], robndbox[4], robndbox[5], robndbox[6], robndbox[7], robndbox[8], robndbox[9], robndbox[10], robndbox[11], robndbox[12], label, difficult) writer.save(targetFile=filename) return
def savePascalVocFormat(self, filename, shapes, imagePath, imageData, lineColor=None, fillColor=None, databaseSrc=None): imgFolderPath = os.path.dirname(imagePath) #加载文件所在路径 imgFolderName = os.path.split(imgFolderPath)[-1] #获取文件所在文件夹名称 imgFileName = os.path.basename(imagePath) #获取文件名(包含文件扩展名,即形如1.jpg) imgFileNameWithoutExt = os.path.splitext(imgFileName)[ 0] #os.path.splitext将文件名和扩展名分开,这里只取文件名 # Read from file path because self.imageData might be empty if saving to # Pascal format image = QImage() image.load(imagePath) #加载图像 imageShape = [ image.height(), image.width(), 1 if image.isGrayscale() else 3 ] #获取图像的width,height和depth writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt, imageShape, localImgPath=imagePath) writer.verified = self.verified for shape in shapes: points = shape['points'] label = shape['label'] # Add Chris difficult = int(shape['difficult']) direction = shape['direction'] isRotated = shape['isRotated'] # if shape is normal box, save as bounding box # print('direction is %lf' % direction) if not isRotated: bndbox = LabelFile.convertPoints2BndBox(points) writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, difficult) else: #if shape is rotated box, save as rotated bounding box robndbox = LabelFile.convertPoints2RotatedBndBox(shape) writer.addRotatedBndBox(robndbox[0], robndbox[1], robndbox[2], robndbox[3], robndbox[4], label, difficult) writer.save(targetFile=filename) #保存 return