Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writer.addObject is not working #7

Open
shreesurya opened this issue Dec 2, 2020 · 1 comment
Open

writer.addObject is not working #7

shreesurya opened this issue Dec 2, 2020 · 1 comment

Comments

@shreesurya
Copy link

import os
import numpy as np
from pascal_voc_writer import Writer

bboxList = [(77, 238, 230, 458),(99, 298, 0, 48),(1, 2, 3, 4)]
objectLabelList = ['left','right','front'] 
imageDirPathBuffer = '__Path__/name.jpg'

anno_filename = 'annotations.csv'
w, h = 1920, 1080
def convert2xml(bboxList, objectLabelList, imageDirPathBuffer):
    writer = Writer(imageDirPathBuffer,w,h)
    annotation_file = open(anno_filename, 'a')
    for idx, item in enumerate(bboxList):
        x1, y1, x2, y2 = bboxList[idx]
        writer.addObject(str(objectLabelList[idx]), x1, y1, x2, y2)
        annotation_file.write('__Path__' + '/' + 'name.jpg'+ ',' +
                                           ','.join(map(str, bboxList[idx])) + ',' + (objectLabelList[idx])
                                            + '\n')
        annotation_file.close()
        base = os.path.basename(imageDirPathBuffer)
        baseName = os.path.splitext(base)[0]
        save_dir = 'annotations/annotations_voc/'
        save_path = save_dir + baseName + '.xml'
        if(not os.path.exists(save_dir)):
            os.mkdir(save_dir)
        writer.save(save_path)
        writer = None
        print(bboxList)
        print(objectLabelList)
        print(x1)


convert2xml(bboxList, objectLabelList, imageDirPathBuffer)

It generates xml with only first coordinates i.e. (77, 238, 230, 458) where I want to write xml with all the coordinates.

@Jordan-Pierce
Copy link

Pretty old, but others who see this, the issue looks like the file is being written within the for-loop, and then the writer is set to None before going on to the next annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants