Exemplo n.º 1
0
    def saveBehavior(self, behaviors, imagePath):
        imgFolderPath = os.path.dirname(imagePath)
        imgFolderName = os.path.split(imgFolderPath)[-1]
        imgFileName = os.path.basename(imagePath)
        image = QImage()
        image.load(imagePath)
        imageShape = [
            image.height(),
            image.width(), 1 if image.isGrayscale() else 3
        ]
        writer = PascalVocWriter(imgFolderName,
                                 imgFileName,
                                 imageShape,
                                 localImgPath=imagePath)
        writer.verified = self.verified

        for behavior in behaviors:
            label = behavior.label
            self_id = behavior.self_id
            start_frame = behavior.start_frame
            end_frame = behavior.end_frame
            if len(behavior.shapes) != 0:
                print('add the shapes to list')
                writer.addBehavior(label, self_id, start_frame, end_frame,
                                   behavior.shapes)
            else:
                writer.addBehavior(label, self_id, start_frame, end_frame)

        writer.save(targetFile=(imgFolderPath + "/behavior.xml"))
        return
Exemplo n.º 2
0
    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, imgFileName,
                                 imageShape,localImgPath=imagePath)
        writer.verified = self.verified

        for shape in shapes:
            points = shape['points']
            label = shape['label']
            # Add Chris
            difficult = int(shape['difficult'])
            illumination = str(shape['illumination'])
            distince = str(shape['distince'])
            yaw = str(shape['yaw'])
            pitch = str(shape['pitch'])
            roll = str(shape['roll'])
            glasses = str(shape['glasses']) # yyk add
            bndbox = LabelFile.convertPoints2BndBox(points)
            writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, difficult, illumination, distince, yaw, pitch, roll, glasses) 

        writer.save(targetFile=filename)
        return
Exemplo n.º 3
0
    def savePascalVocFormat(self, filename, shapes, imagePath, imageData,
                            lineColor=None, fillColor=None, databaseSrc=None , usrname = 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, imgFileName,
                                 imageShape, localImgPath=imagePath , usrname=usrname)
        writer.verified = self.verified

        for shape in shapes:
            points = shape['points']
            label = shape['label']
            # Add Chris
            difficult = int(shape['difficult'])
            bndbox = LabelFile.convertPoints2BndBox(points)
            writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, difficult)

        writer.save(targetFile=filename)
        return
Exemplo n.º 4
0
 def savePascalVocFormat(self, filename, shapes, imagePath):
     imgFolderPath = os.path.dirname(imagePath)
     imgFolderName = os.path.split(imgFolderPath)[-1]
     imgFileName = os.path.basename(imagePath)
     image = QImage()
     image.load(imagePath)
     imageShape = [
         image.height(),
         image.width(), 1 if image.isGrayscale() else 3
     ]
     writer = PascalVocWriter(imgFolderName,
                              imgFileName,
                              imageShape,
                              localImgPath=imagePath)
     writer.verified = self.verified
     for shape in shapes:
         points = shape['points']
         label = "cell"
         # label = shape['label']
         difficult = int(shape['difficult'])
         bndbox = LabelFile.convertPoints2BndBox(points)
         writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label,
                          difficult)
     writer.save(targetFile=filename)
     return
Exemplo n.º 5
0
def savePascalVocFormat(filename, shapes, imagePath):
    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 = misc.imread(imagePath, mode="RGB")
    [height, width, dim] = image.shape
    imageShape = [height, width, dim]
    writer = PascalVocWriter(imgFolderName, imgFileName,
                             imageShape, localImgPath=imagePath)
    writer.verified = False

    for shape in shapes:
        label = shape[0]
        box = shape[1]
        xmin = box[0][0]
        ymin = box[0][1]
        xmax = box[1][0]
        ymax = box[1][1]
        difficult = shape[2]
        writer.addBndBox(xmin, ymin, xmax, ymax, label, difficult)
    writer.save(targetFile=filename)
    return
Exemplo n.º 6
0
    def save_pascal_voc_format(self, filename, shapes, image_path, image_data,
                               line_color=None, fill_color=None, title="", database_src=None):
        img_folder_path = os.path.dirname(image_path)
        img_folder_name = os.path.split(img_folder_path)[-1]
        img_file_name = os.path.basename(image_path)
        # imgFileNameWithoutExt = os.path.splitext(img_file_name)[0]
        # Read from file path because self.imageData might be empty if saving to
        # Pascal format
        if isinstance(image_data, QImage):
            image = image_data
        else:
            image = QImage()
            image.load(image_path)
        image_shape = [image.height(), image.width(),
                       1 if image.isGrayscale() else 3]
        writer = PascalVocWriter(img_folder_name, img_file_name,
                                 image_shape, local_img_path=image_path,title=title)
        writer.verified = self.verified

        for shape in shapes:
            points = shape['points']
            label = shape['label']
            # Add Chris
            difficult = int(shape['difficult'])
            bnd_box = LabelFile.convert_points_to_bnd_box(points)
            writer.add_bnd_box(bnd_box[0], bnd_box[1], bnd_box[2], bnd_box[3], label, difficult)

        writer.save(target_file=filename)
        return
Exemplo n.º 7
0
    def savePascalVocFormat(self,
                            filename,
                            shapes,
                            imagePath,
                            imageData,
                            saveTimes=0,
                            opUserName="******",
                            opTime="无",
                            isCheck=False,
                            lastCheckTime=None,
                            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
        filePath = ustr(imagePath)
        unicodeFilePath = ustr(filePath)
        if filePath.split('.')[-1] == 'tif':
            Img = cv2.imdecode(np.fromfile(unicodeFilePath, dtype=np.uint8),
                               -1)
            height, width, bytesPerComponent = Img.shape
            bytesPerLine = 3 * width
            cv2.cvtColor(Img, cv2.COLOR_BGR2RGB, Img)
            image = QImage(Img.data, width, height, bytesPerLine,
                           QImage.Format_RGB888)
        else:
            image = QImage()
            image.load(imagePath)
        imageShape = [
            image.height(),
            image.width(), 1 if image.isGrayscale() else 3
        ]
        writer = PascalVocWriter(imgFolderName,
                                 imgFileName,
                                 imageShape,
                                 saveTimes,
                                 opUserName,
                                 opTime,
                                 isCheck,
                                 lastCheckTime,
                                 localImgPath=imagePath)
        writer.verified = self.verified

        for shape in shapes:
            points = shape['points']
            label = shape['label']
            # Add Chris
            difficult = int(shape['difficult'])
            bndbox = LabelFile.convertPoints2BndBox(points)
            writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label,
                             difficult)

        writer.save(targetFile=filename)
        return
Exemplo n.º 8
0
    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,
                                 imgFileName,
                                 imageShape,
                                 localImgPath=imagePath)
        writer.verified = self.verified

        for shape in shapes:
            points = shape['points']
            label = shape['label']
            difficult = int(shape['difficult'])
            tetragon = shape['tetragon']
            angle = int(round(shape['deg']))
            d3 = shape['shape3D']
            if d3 == False:
                if tetragon == False:
                    bndbox = LabelFile.convertPoints2BndBox(points)
                    writer.addBndBox(bndbox[0], bndbox[1], bndbox[2],
                                     bndbox[3], label, difficult, tetragon,
                                     angle)
                elif tetragon == True:
                    writer.addBndBox2(points, label, difficult, tetragon,
                                      angle)
            elif d3:
                writer.addBndBox3(d3, points, label, angle, difficult)

        writer.save(targetFile=filename)
        return
Exemplo n.º 9
0
    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,
                                 imgFileName,
                                 imageShape,
                                 localImgPath=imagePath)
        writer.verified = self.verified

        for shape in shapes:
            label = shape['label']
            pose = shape['pose']
            unique = shape['unique']
            # Add Chris
            difficult = int(shape['difficult'])
            x = shape['x']
            y = shape['y']
            polygontype = shape['polygonType']
            if polygontype == 'rectangle':
                xbox, ybox = self.convertPoints2BndBox(x, y)
            else:
                xbox, ybox = x, y
            inpolygon = shape['inpolygon']
            writer.addBndBox(label, pose, unique, difficult, polygontype, xbox,
                             ybox, inpolygon)

        writer.save(targetFile=filename)
        return
Exemplo n.º 10
0
    def savePascalVocFormat(self, filename, shapes, imagePath, imageData,type,
                            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=cv2.imread(imagePath)
        imageShape = [image.shape[0], image.shape[1],image.shape[2]]

        writer = PascalVocWriter(imgFolderName, imgFileName,# 初始化写入类
                                 imageShape,databaseSrc,imagePath)
        writer.verified = self.verified


        for shape in shapes:                                # 保存点集 points label type difficult
            points = shape['points']
            label = shape['label']
            # Add Chris
            difficult = int(shape['difficult'])
            type = int(shape['type'])
            order = int(shape['order'])
            current_id = int(shape['current_id'])
            track_id = int(shape['track_id'])
            occluded = int(shape['occluded'])
            exist_3D = int(shape['exist_3D'])

            # 当3D框存在对应的2D框,就无需保存,与2D框的属性保存在一起
            if type == ShapeType['cuboid'].value and shape['exist_2D']: continue


            if type in [ShapeType['rect'].value,ShapeType['point'].value]:
                points_3D=[]
                if shape['exist_3D']:
                    for tmp_shape in shapes:
                        if tmp_shape['current_id']==shape['current_id'] and int(tmp_shape['type'])==ShapeType['cuboid'].value:
                            points_3D = tmp_shape['points']
                bndbox = LabelFile.convertPoints2BndBox(points)
                writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, difficult, type,order,current_id,track_id,occluded,exist_3D,points_3D)
            else:
                writer.addLine(points, label, difficult, type, order,current_id,track_id,occluded,exist_3D)
        writer.save(targetFile=filename)
        return
Exemplo n.º 11
0
    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
        imageShape = [
            imageData.height(),
            imageData.width(), 1 if imageData.isGrayscale() else 3
        ]
        writer = PascalVocWriter(imgFolderName,
                                 imgFileName,
                                 imageShape,
                                 localImgPath=imagePath)
        writer.verified = self.verified

        for shape in shapes:
            points = shape['points']
            label = shape['label']
            bbox_source = shape['bbox_source']
            id_number = shape['id_number']
            score = shape['score']
            mask = shape['mask']
            # try:
            #     score = shape['score']
            # except KeyError:
            #     score = -1
            # Add Chris
            difficult = int(shape['difficult'])
            bndbox = LabelFile.convertPoints2BndBox(points, label)
            writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label,
                             difficult, bbox_source, id_number, score, mask)

        writer.save(targetFile=filename)
        return
Exemplo n.º 12
0
    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)
        image = QImage()
        image.load(imagePath)
        imageShape = [image.height(), image.width(), 1 if image.isGrayscale() else 3]
        writer = PascalVocWriter(imgFolderName, imgFileName, imageShape, localImgPath=imagePath)
        writer.verified = self.verified
        for shape in shapes:
            points = shape['points']
            label = shape['label']
            # difficult = int(shape['difficult'])
            contour_points = shape['contour_points']
            confidence = shape['confidence']
            contourEdited = shape['contourEdited']
            bndbox = LabelFile.convertPoints2BndBox(points)
            writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, contour_points, confidence, contourEdited)

        writer.save(targetFile=filename)
        return
Exemplo n.º 13
0
    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)
        # 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,
                                 imgFileName,
                                 imageShape,
                                 localImgPath=imagePath)
        writer.verified = self.verified

        for shape in shapes:
            points = shape['points']
            label = shape['label']
            # Add Chris
            difficult = int(shape['difficult'])
            # # Add Jerry
            shapeType = shape["shapeType"]

            writer.addShape(shapeType, label, points, difficult)

        writer.save(targetFile=filename)
        return
Exemplo n.º 14
0
    def savePascalVocFormat(self,
                            filename,
                            shapes,
                            imagePath,
                            imageData,
                            lineColor=None,
                            fillColor=None,
                            databaseSrc=None,
                            objects=None,
                            geoInfo=None):
        """
        :param filename:
        :param shapes:
        :param imagePath:
        :param imageData:
        :param lineColor:
        :param fillColor:
        :param databaseSrc:
        :param objectItems: is the objectItems data for xml file to write
        :return:
        """
        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,
                                 imgFileName,
                                 imageShape,
                                 localImgPath=imagePath)
        writer.verified = self.verified
        try:
            writer.latitude = geoInfo[0]
            writer.longitude = geoInfo[1]
            writer.altitude = geoInfo[2]
        except:
            print("no geoinfo in labelfile savePascalFormat")
        count = 0
        for shape in shapes:
            points = shape['points']
            label = shape['label']
            # Add Chris
            difficult = int(shape['difficult'])
            bndbox = LabelFile.convertPoints2BndBox(points)
            try:
                writer.addBndBox(bndbox[0],
                                 bndbox[1],
                                 bndbox[2],
                                 bndbox[3],
                                 label,
                                 difficult,
                                 objectItems=objects[count])
            except Exception as e:
                print('Exception in savePascalVocFormat labelFile.py:', str(e))
                writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3],
                                 label, difficult)
            count += 1
        writer.save(targetFile=filename)

        return
Exemplo n.º 15
0
    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,
                                 imgFileName,
                                 imageShape,
                                 localImgPath=imagePath)
        writer.verified = self.verified

        enable_del = False
        init_read_save_file = False
        new_shapes = []

        for shape in shapes:
            points = shape['points']
            label = shape['label']
            if label == "del":
                if not init_read_save_file:
                    init_read_save_file = True
                    file_img = imgFolderPath + "/" + imgFileName
                    img = cv2.imread(file_img)

                #draw black rectangle
                cv2.rectangle(img, (int(points[0][0]), int(points[0][1])),
                              (int(points[2][0]), int(points[2][1])),
                              (0, 0, 0), -1)
                continue
            # copy data
            new_shapes.append(shape)

        #save file
        if init_read_save_file:
            b = cv2.imwrite(file_img, img)
            print("save new file {} = {}".format(file_img, b))

        #save xml
        for shape in new_shapes:
            points = shape['points']
            label = shape['label']
            # Add Chris
            difficult = int(shape['difficult'])
            bndbox = LabelFile.convertPoints2BndBox(points)
            writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], 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)
        #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, imgFileName,
                                 imageShape, localImgPath=imagePath)
        writer.verified = self.verified

        for shape in shapes:
            points = shape['points']
            label = shape['label']

            # Add Chris
            gender = int(shape['ismale'])

            age = int(shape['age'])

            blurriness = int(shape['blur'])

            if shape['laugh']:
                emotion = 1
            elif shape['shock']:
                emotion = 2
            else:
                emotion = 0

            if shape['dim']:
                illumination = 1
            elif shape['bright']:
                illumination = 2
            elif shape['backlight']:
                illumination = 3
            elif shape['yinyang']:
                illumination = 4
            else:
                illumination = 0

            if shape['partial']:
                occlusion = 1
            elif shape['heavy']:
                occlusion = 2
            elif shape['sunglasses']:
                occlusion = 3
            else:
                occlusion = 0

            if shape['yaw_30']:
                yaw = 1
            elif shape['yaw_60']:
                yaw = 2
            else:
                yaw = 0

            if shape['roll_20']:
                roll = 1
            elif shape['roll_45']:
                roll = 2
            else:
                roll = 0

            if shape['pitch_20up']:
                pitch = 1
            elif shape['pitch_45up']:
                pitch = 2
            elif shape['pitch_20down']:
                pitch = 3
            elif shape['pitch_45down']:
                pitch = 4
            else:
                pitch = 0

            bndbox = LabelFile.convertPoints2BndBox(points)
            writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, gender, age,
                             emotion, illumination, blurriness, occlusion, yaw, roll, pitch)

        writer.save(targetFile=filename)
        return
Exemplo n.º 17
0
    def savePascalVocFormat(self, filename, shapes, imagePath,
                            model=None, canvas=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, imgFileName,
                                 imageShape, model, localImgPath=imagePath,
                                 hsv=canvas.hsv)
        writer.verified = self.verified

        maskFilePath = os.path.dirname(filename)
        fName = os.path.basename(filename).split(".")[0]
        # create mask folder
        maskFilePath = os.path.dirname(maskFilePath)
        maskFilePath = os.path.join(maskFilePath, "masks")
        if not os.path.exists(maskFilePath):
            os.makedirs(maskFilePath)

        idx = 1
        for shape in shapes:
            # generate mask filename
            label = shape['label']
            maskType = shape['maskType']
            points = shape['points']

            if maskType == 0: # bounding box

                difficult = int(shape['difficult'])
                bndbox = LabelFile.convertPoints2BndBox(points)
                writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, difficult, maskType)

            elif maskType == 1:  # get mask for line
                maskFileName = fName + "_" + str(idx) + "_" + str(label) + ".png"
                maskFile = os.path.join(maskFilePath,maskFileName)
                # use tmask to get bounding box and maskPixmap for segment
                tmask = canvas.getMask(points, maskType)
                segment,x1,y1,x2,y2 = libs.np2qt.getSegment(tmask, maskFile)
                #TODO: make string (list of tuples)
                strPoints = str(points)
                writer.addBndBox(x1, y1, x2, y2, label, 0, str(maskType),
                                  strPoints,segment)

                idx +=1
            elif maskType == 2: # BOX Mask
                maskFileName = fName + "_" + str(idx) + "_" + str(label) + ".png"
                maskFile = os.path.join(maskFilePath,maskFileName)
                # use tmask to get bounding box and maskPixmap for segment
                tmask = canvas.getMask(points, maskType)
                segment,x1,y1,x2,y2 = libs.np2qt.getBoxSegment(tmask, imagePath, canvas.hsv, maskFile)
                #TODO: make string (list of tuples)
                strPoints = str(points)
                writer.addBndBox(x1, y1, x2, y2, label, 0, str(maskType),
                                  strPoints,segment)

                idx +=1

        writer.save(targetFile=filename)

        return