def test_can_add_objects_to_xml(): utils.initialize_xml_file('foo.png', (123, 234)) boxes = [] boxes.append([0, (17, 29), (420, 69)]) boxes.append([0, (27, 19), (230, 45)]) utils.add_objects_to_xml_file('foo', boxes) assert line_written_properly_to_xml('xmin', '17')
im_path = os.path.join(config.im_dir, new_path + '_boxes' + image_ext) xml_path = os.path.join(config.im_dir, new_path + '.xml') # If there are already some labels for this box, load that image if os.path.exists(im_path): image = cv2.imread(im_path) else: image = cv2.imread(orig_image_path) # Grab the image size (very important) and draw height, width = image.shape[:2] update_image() # If there is not an xml file for this image, initialize one if not os.path.exists(xml_path): utils.initialize_xml_file(xml_path, (width, height)) ### USER INPUT LOOP ### ####################### # In a loop, check for any keys of interest pressed as well as # mouse clicks. The left mouse button is used for drag-and-drop # selection of box vertices, the right mouse button deletes the # last box. # # "ESC" is for abort # "BACKSPACE" is for DELETE LAST # "R" is for RESTART IMAGE # "0-9" is for CLASS selection # "SPACE" is for NEXT IMAGE # "ENTER" is for SAVING CURRENT # "awsd" is for MOVING display # -/+ keys for ZOOM while True: key = cv2.waitKey(1) & 0xFF
def test_can_write_size(): utils.initialize_xml_file('foo.png', (1234, 2345, 3)) assert line_written_properly_to_xml('width', '1234') assert line_written_properly_to_xml('height', '2345') assert line_written_properly_to_xml('depth', '3')
def test_can_write_filename_line(): utils.initialize_xml_file('foo.png', (0, 0)) assert line_written_properly_to_xml('filename', 'foo.png')
def test_can_write_folder_line(): utils.initialize_xml_file('foo.png', (0, 0)) assert line_written_properly_to_xml('folder', 'data/documents')
def test_can_write_annotation_tags_without_extension(): utils.initialize_xml_file('foo', (0, 0)) assert annotation_tags_exist()
def test_can_write_annotation_tags(): utils.initialize_xml_file('foo.png', (0, 0)) assert annotation_tags_exist()
import detection_utils as utils import os import config for csv_file in os.listdir(config.im_dir): if not csv_file.endswith('.csv'): continue xml_file = os.path.splitext(csv_file)[0][:-6] + '.xml' csv_file = os.path.join(config.im_dir, csv_file) xml_file = os.path.join(config.im_dir, xml_file) contents = utils.get_csv_contents(csv_file) size = (contents[0][5], contents[0][6]) if len(contents) == 0: continue utils.initialize_xml_file(xml_file, size) utils.add_objects_to_xml_file(xml_file, contents)