def test_open(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 0) roi.push(100.0, 100.0) a.push(roi, i % len(tool.class_list)) tool.annotations.append(a) appMenu = AppMenu(tool) complete = appMenu._open('file.oaf') self.assertTrue(complete) self.assertEqual(tool.class_count, [6, 6, 3]) self.assertTrue(tool.project_open) self.assertTrue(tool.saved) self.assertEqual(tool.top_colors_used, tool.colorspace) self.assertEqual(tool.top_colors_free, tool.top_colors[3:]) appMenu = AppMenu(tool) complete = appMenu._open('') self.assertFalse(complete)
def test_import_files_in_directory(self): tool = AnnotationTool() tool.load_app(True) tool.annotations = [Annotation(), Annotation(), Annotation()] tool.file_list = ['file1.jpg', 'file2.jpg', 'file3.png'] tool.current_file = 0 tool.class_list = [] tool.img = MockImg(640, 480) appMenu = AppMenu(tool) self.assertTrue(tool.saved) complete = appMenu._import_files_in_directory('path/', MockMeta(6)) self.assertTrue(complete) self.assertEqual(len(tool.annotations), 3) self.assertFalse(tool.saved) tool.saved = True self.assertTrue(tool.saved) complete = appMenu._import_files_in_directory('path/', MockMeta(6)) self.assertTrue(complete) self.assertEqual(len(tool.annotations), 3) self.assertFalse(tool.saved) tool.saved = True self.assertTrue(tool.saved) complete = appMenu._import_files_in_directory('', MockMeta(6)) self.assertFalse(complete) self.assertEqual(len(tool.annotations), 3) self.assertTrue(tool.saved)
def test_csv_exporter(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 0) roi.push(100.0, 100.0) a.push(roi, i % len(tool.class_list)) tool.annotations.append(a) appMenu = AppMenu(tool) complete = appMenu._csv_exporter('test') self.assertTrue(complete) appMenu = AppMenu(tool) complete = appMenu._csv_exporter('test.csv') self.assertTrue(complete) appMenu = AppMenu(tool) complete = appMenu._csv_exporter('') self.assertFalse(complete)
def test_next_image(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.num_pages = 1 for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0,0) roi.push(100.0,100.0) a.push(roi, i%len(tool.class_list)) tool.annotations.append(a) toolbar = Toolbar(tool) self.assertEqual(tool.current_file, 0) truth = [1, 2, 3, 4, 4] for i in range(5): toolbar._next_image() self.assertEqual(tool.current_file, truth[i])
def test_change_image(self): tool = AnnotationTool() tool.load_app(True) tool.file_list = [] tool.annotations = [] tool.current_file = 0 tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.num_pages = 1 tool.class_count = [5, 5, 5] for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0,0) roi.push(100.0,100.0) a.push(roi, p%len(tool.class_list)) tool.annotations.append(a) tool.img = MockImg() tool._draw_workspace() navigator = Navigator(tool) self.assertEqual(tool.current_file, 0) navigator.change_image(1) self.assertEqual(tool.current_file, 1)
def test_draw_image_navigator(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.num_pages = 1 for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0,0) roi.push(100.0,100.0) a.push(roi, i%len(tool.class_list)) tool.annotations.append(a) toolbar = Toolbar(tool) nav_frame = toolbar.toolbar_frame.winfo_children()[0] nav_frame_children = nav_frame.winfo_children() self.assertEqual(len(nav_frame_children), 3) self.assertEqual(nav_frame_children[0].cget('text'), "Page 1/2")
def test_draw_class_selection_menu(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.num_pages = 1 tool.class_count = [5, 5, 5] for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0,0) roi.push(100.0,100.0) a.push(roi, p%len(tool.class_list)) tool.annotations.append(a) toolbar = Toolbar(tool) option_menu = toolbar.toolbar_frame.winfo_children()[2] self.assertEqual(option_menu.winfo_name(), '!optionmenu')
def test_delete_from_project(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.num_pages = 1 tool.class_count = [5, 5, 5] for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0,0) roi.push(100.0,100.0) a.push(roi, p%len(tool.class_list)) tool.annotations.append(a) toolbar = Toolbar(tool) self.assertEqual(len(tool.annotations) , 5) self.assertEqual(len(tool.file_list) , 5) self.assertListEqual(tool.class_count, [5,5,5]) toolbar._delete_from_project() self.assertEqual(len(tool.annotations) , 4) self.assertEqual(len(tool.file_list) , 4) self.assertListEqual(tool.class_count, [4,4,4])
def test_delete_from_project_button(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.num_pages = 1 for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0,0) roi.push(100.0,100.0) a.push(roi, i%len(tool.class_list)) tool.annotations.append(a) toolbar = Toolbar(tool) button = toolbar.toolbar_frame.winfo_children()[1] self.assertEqual(button.cget('text'), '') self.assertEqual(button.cget('width'), 40) self.assertEqual(button.cget('height'), 40)
def test_reset_image(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['blue', 'green', 'red'] tool.current_file = 0 tool.class_count = [0, 15, 0] tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 0) roi.push(100.0, 100.0) a.push(roi, 1) tool.annotations.append(a) tool._draw_workspace() self.assertEqual(tool.annotations[tool.current_file].size(), 3) complete = tool._reset_image() self.assertEqual(tool.annotations[tool.current_file].size(), 0) self.assertTrue(complete) tool.window.destroy()
def test_on_click(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['blue', 'green', 'red'] tool.current_file = 0 tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 0) roi.push(100.0, 100.0) a.push(roi, random.randint(0, 2)) tool.annotations.append(a) tool._draw_workspace() # Click Top complete = tool._on_click(Event(10, 0)) self.assertTrue(complete) self.assertEqual('TOP', tool.box_resize_mode) self.assertEqual(0, tool.resize_box_id) # Click Bottom complete = tool._on_click(Event(10, 100 / tool.aspect_ratio)) self.assertTrue(complete) self.assertEqual('BOTTOM', tool.box_resize_mode) self.assertEqual(0, tool.resize_box_id) # Click Left complete = tool._on_click(Event(0, 60)) self.assertTrue(complete) self.assertEqual('LEFT', tool.box_resize_mode) self.assertEqual(0, tool.resize_box_id) # Click Right complete = tool._on_click(Event(100 / tool.aspect_ratio, 60)) self.assertTrue(complete) self.assertEqual('RIGHT', tool.box_resize_mode) self.assertEqual(0, tool.resize_box_id) # Click elsewhere to create a new box complete = tool._on_click(Event(60, 60)) self.assertTrue(complete) self.assertEqual('NEW', tool.box_resize_mode) tool.window.destroy()
def test_draw_canvas(self): class MockImg(object): def __init__(self): self.size = [640, 480] tool = AnnotationTool() tool.load_app(True) tool.annotations = [] tool.class_list = [] # Empty Project complete = tool.draw_canvas() self.assertTrue(complete) self.assertTrue(hasattr(tool, 'canvas')) self.assertFalse(hasattr(tool, 'aspect_ratio')) self.assertFalse(hasattr(tool, 'boxes')) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['blue', 'green', 'red'] tool.current_file = 0 tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 0) roi.push(100.0, 100.0) a.push(roi, random.randint(0, 2)) tool.annotations.append(a) complete = tool.draw_canvas() self.assertTrue(complete) self.assertTrue(hasattr(tool, 'canvas')) self.assertTrue(hasattr(tool, 'aspect_ratio')) self.assertTrue(hasattr(tool, 'boxes')) self.assertEqual(tool.aspect_ratio, 640 / (1024 - 200)) self.assertEqual(3, len(tool.boxes)) tool.window.destroy()
def test_select_image_action(self): tool = AnnotationTool() tool.load_app(True) tool.annotations = [Annotation(), Annotation(), Annotation()] appMenu = AppMenu(tool) appMenu.select_image() appMenu.prompt_entry.insert(0, "1") complete = appMenu.select_image_action() self.assertTrue(complete) appMenu.select_image() appMenu.prompt_entry.insert(0, "4") complete = appMenu.select_image_action() self.assertFalse(complete) appMenu.select_image() appMenu.prompt_entry.insert(0, "-1") complete = appMenu.select_image_action() self.assertFalse(complete)
def test_new(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.class_count = [0, 15, 0] tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 0) roi.push(100.0, 100.0) a.push(roi, 1) tool.annotations.append(a) tool._draw_workspace() appMenu = AppMenu(tool) complete = appMenu._new() self.assertTrue(complete) self.assertEqual(tool.file_list, []) self.assertTrue(tool.project_open) self.assertEqual(tool.annotations, []) self.assertEqual(tool.top_colors_free, tool.top_colors) self.assertEqual(tool.top_colors_used, []) self.assertEqual(tool.class_count, []) self.assertEqual(tool.current_file, 0) self.assertEqual(tool.class_list, []) self.assertEqual(tool.colorspace, [])
def test_draw_workspace(self): class MockImg(object): def __init__(self): self.size = [640, 480] tool = AnnotationTool() tool.load_app(True) tool.annotations = [] tool.class_list = [] # Empty Project complete = tool._draw_workspace() self.assertTrue(complete) self.assertTrue(hasattr(tool, 'background')) self.assertTrue(hasattr(tool, 'app_menu')) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['blue', 'green', 'red'] tool.current_file = 0 tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 0) roi.push(100.0, 100.0) a.push(roi, random.randint(0, 2)) tool.annotations.append(a) complete = tool._draw_workspace() self.assertTrue(complete) self.assertTrue(hasattr(tool, 'background')) self.assertTrue(hasattr(tool, 'app_menu')) tool.window.destroy()
def test_draw_box(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.class_count = [5, 5, 5] for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 0) roi.push(100.0, 100.0) a.push(roi, p % len(tool.class_list)) tool.annotations.append(a) tool.top_colors_free = ['#00FFFF', '#FF00FF', '#FFFF00'] tool.top_colors_used = ['#0000FF', '#FF0000', '#00FF00'] tool.img = MockImg() tool._draw_workspace() canvas_children = tool.canvas.winfo_children() ibox = InteractiveBox(tool, 10, 10, 200, 200, tool.colorspace[0]) self.assertEqual(len(canvas_children), 3) ibox.draw_box(0) canvas_children = tool.canvas.winfo_children() self.assertTrue(hasattr(ibox, 'rect')) self.assertTrue(hasattr(ibox, 'close_button')) self.assertEqual(len(canvas_children), 4)
def test_on_release(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['blue', 'green', 'red'] tool.class_count = [0, 0, 0] tool.current_file = 0 tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) tool.annotations.append(a) tool._draw_workspace() tool._on_click(Event(10, 10)) for i in range(11, 31): tool._on_move_press(Event(i, i)) complete = tool._on_release(Event(30, 30)) self.assertTrue(complete) self.assertEqual(0, tool.annotations[0].label[0]) self.assertEqual([1, 0, 0], tool.class_count) self.assertEqual([10 * tool.aspect_ratio, 10 * tool.aspect_ratio], tool.annotations[0].roi[0].points[0]) self.assertEqual([30 * tool.aspect_ratio, 30 * tool.aspect_ratio], tool.annotations[0].roi[0].points[1]) self.assertFalse(tool.saved) self.assertEqual(tool.box_resize_mode, 'NEW') tool.window.destroy()
def test_init(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['#0000FF', '#FF0000', '#00FF00'] tool.current_file = 0 tool.num_pages = 1 toolbar = Toolbar(tool) self.assertEqual(toolbar.root_app, tool) self.assertEqual(toolbar.toolbar_width, tool.window_width) self.assertEqual(toolbar.toolbar_height, tool.toolbar_height) self.assertEqual(len(toolbar.toolbar_frame.winfo_children()), 0) for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0,0) roi.push(100.0,100.0) a.push(roi, i%len(tool.class_list)) tool.annotations.append(a) toolbar = Toolbar(tool) self.assertEqual(toolbar.root_app, tool) self.assertEqual(toolbar.toolbar_width, tool.window_width) self.assertEqual(toolbar.toolbar_height, tool.toolbar_height) self.assertEqual(len(toolbar.toolbar_frame.winfo_children()), 3)
def test_Annotation(self): a = Annotation() self.assertTrue(hasattr(a, 'roi')) self.assertEqual(len(a.roi), 0) self.assertTrue(hasattr(a, 'label')) self.assertEqual(len(a.label), 0) self.assertTrue(hasattr(a, 'rotation')) a.rotation = 3 self.assertEqual(a.rotation, 3) for p in range(5): roi = ROI() roi.push(0, 1) roi.push(50.0, 51.0) roi.push(100, 101.0) a.push(roi, p % 3) bytes_arr = a.to_bytes() self.assertListEqual(bytes_arr, [ b'\x05', b'\n', b'\x03', b'\n', b'\x00\x03', b'\n', b'\x00\x00\x00\x00', b'\n', b'\x00\x00\x80?', b'\n', b'\x00\x00HB', b'\n', b'\x00\x00LB', b'\n', b'\x00\x00\xc8B', b'\n', b'\x00\x00\xcaB', b'\n', b'\x00\x00', b'\n', b'\x00\x03', b'\n', b'\x00\x00\x00\x00', b'\n', b'\x00\x00\x80?', b'\n', b'\x00\x00HB', b'\n', b'\x00\x00LB', b'\n', b'\x00\x00\xc8B', b'\n', b'\x00\x00\xcaB', b'\n', b'\x00\x01', b'\n', b'\x00\x03', b'\n', b'\x00\x00\x00\x00', b'\n', b'\x00\x00\x80?', b'\n', b'\x00\x00HB', b'\n', b'\x00\x00LB', b'\n', b'\x00\x00\xc8B', b'\n', b'\x00\x00\xcaB', b'\n', b'\x00\x02', b'\n', b'\x00\x03', b'\n', b'\x00\x00\x00\x00', b'\n', b'\x00\x00\x80?', b'\n', b'\x00\x00HB', b'\n', b'\x00\x00LB', b'\n', b'\x00\x00\xc8B', b'\n', b'\x00\x00\xcaB', b'\n', b'\x00\x00', b'\n', b'\x00\x03', b'\n', b'\x00\x00\x00\x00', b'\n', b'\x00\x00\x80?', b'\n', b'\x00\x00HB', b'\n', b'\x00\x00LB', b'\n', b'\x00\x00\xc8B', b'\n', b'\x00\x00\xcaB', b'\n', b'\x00\x01', b'\n' ]) for i in range(5): self.assertEqual(len(a.roi[0].points), 3) self.assertEqual(a.label[0], i % 3) a.pop() self.assertEqual(len(a.roi), 4 - i) self.assertEqual(len(a.label), 4 - i)
def file_to_annotation(self, file, meta=None): ''' Creates an Annotation object based on the image. Parameters ---------- file : STRING Path and Filename of Image to be annotated. meta : exif.Image object Used for testing purposes only. Returns ------- None. ''' self.root_app.annotations.append(Annotation()) # EXIF data is not present in all images (e.g., png files). If there # is EXIF data, use it to figure out how the image needs to be rotated. try: if self.root_app.window.winfo_ismapped(): meta = exif.Image(file) if meta.has_exif: if 'orientation' in dir(meta): if meta.orientation == 6: self.root_app.annotations[-1].rotation =\ Image.ROTATE_270 elif meta.orientation == 3: self.root_app.annotations[-1].rotation =\ Image.ROTATE_180 elif meta.orientation == 8: self.root_app.annotations[-1].rotation =\ Image.ROTATE_90 # This is the error when no EXIF data is found. except UnpackError: pass return True
def test_SaveOAF(self): annotations = [] file_list = [] class_list = ['winston', 'prince', 'duckie'] colorspace = ['#0000FF', '#FF0000', '#00FF00'] current_file = 4 filename = 'tempfile.oaf' for i in range(5): a = Annotation() a.rotation = 3 file_list.append('file%d.jpg' % i) for p in range(3): roi = ROI() roi.push(0, 1) roi.push(50.0, 51.0) roi.push(100, 101.0) a.push(roi, p % 3) annotations.append(a) byte_arr = SaveOAF(filename, annotations, file_list, class_list, colorspace, current_file, testing=True) byte_arr_copy = [] while len(byte_arr): byte_arr_copy.append(byte_arr.pop(0) + byte_arr.pop(0)) byte_arr = byte_arr_copy del byte_arr_copy byte_truth = [ b'\x01\n', b'\x04\n', b'\x05\n', b'file0.jpg\n', b'\x03\n', b'\x03\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x00\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x01\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x02\n', b'file1.jpg\n', b'\x03\n', b'\x03\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x00\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x01\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x02\n', b'file2.jpg\n', b'\x03\n', b'\x03\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x00\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x01\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x02\n', b'file3.jpg\n', b'\x03\n', b'\x03\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x00\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x01\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x02\n', b'file4.jpg\n', b'\x03\n', b'\x03\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x00\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x01\n', b'\x00\x03\n', b'\x00\x00\x00\x00\n', b'\x00\x00\x80?\n', b'\x00\x00HB\n', b'\x00\x00LB\n', b'\x00\x00\xc8B\n', b'\x00\x00\xcaB\n', b'\x00\x02\n', b'\x03\n', b'winston\n', b'#0000FF\n', b'prince\n', b'#FF0000\n', b'duckie\n', b'#00FF00\n' ] self.assertListEqual(byte_arr, byte_truth) annotations0, file_list0, class_list0, colorspace0, current_file0 =\ LoadOAF(filename, byte_truth) self.assertListEqual(file_list, file_list0) self.assertListEqual(class_list, class_list0) self.assertListEqual(colorspace, colorspace0) self.assertEqual(current_file, current_file0)
def test_on_move_press(self): tool = AnnotationTool() tool.load_app(True) # Annotation added tool.annotations = [] tool.file_list = [] tool.class_list = ['winston', 'prince', 'duckie'] tool.colorspace = ['blue', 'green', 'red'] tool.class_count = [0, 0, 0] tool.current_file = 0 tool.img = MockImg() for i in range(5): a = Annotation() a.rotation = 3 tool.file_list.append('file%d.jpg' % i) tool.annotations.append(a) tool._draw_workspace() tool._on_click(Event(10, 10)) self.assertFalse(hasattr(tool, 'rect')) complete = tool._on_move_press(Event(11, 11)) self.assertTrue(complete) self.assertTrue(hasattr(tool, 'rect')) complete = tool._on_move_press(Event(12, 12)) self.assertTrue(complete) self.assertTrue(hasattr(tool, 'rect')) self.assertTrue(hasattr(tool, 'box_end')) # Create a new Box tool._on_click(Event(10, 10)) for i in range(11, 26): tool._on_move_press(Event(i, i)) tool._on_release(Event(25, 25)) tool.resize_box_id = 0 tool.box_resize_mode = 'RIGHT' self.assertEqual(tool.annotations[0].roi[0].points[1], [25 * tool.aspect_ratio, 25 * tool.aspect_ratio]) complete = tool._on_move_press(Event(20, 25)) self.assertTrue(complete) self.assertEqual(tool.annotations[0].roi[0].points[1], [20 * tool.aspect_ratio, 25 * tool.aspect_ratio]) tool.box_resize_mode = 'LEFT' self.assertEqual(tool.annotations[0].roi[0].points[0], [10 * tool.aspect_ratio, 10 * tool.aspect_ratio]) complete = tool._on_move_press(Event(15, 10)) self.assertTrue(complete) self.assertEqual(tool.annotations[0].roi[0].points[0], [15 * tool.aspect_ratio, 10 * tool.aspect_ratio]) tool.box_resize_mode = 'TOP' self.assertEqual(tool.annotations[0].roi[0].points[0], [15 * tool.aspect_ratio, 10 * tool.aspect_ratio]) complete = tool._on_move_press(Event(15, 15)) self.assertTrue(complete) self.assertEqual(tool.annotations[0].roi[0].points[0], [15 * tool.aspect_ratio, 15 * tool.aspect_ratio]) tool.box_resize_mode = 'BOTTOM' self.assertEqual(tool.annotations[0].roi[0].points[1], [20 * tool.aspect_ratio, 25 * tool.aspect_ratio]) complete = tool._on_move_press(Event(20, 20)) self.assertTrue(complete) self.assertEqual(tool.annotations[0].roi[0].points[1], [20 * tool.aspect_ratio, 20 * tool.aspect_ratio]) tool.window.destroy()
def test_draw_menu(self): tool = AnnotationTool() tool.load_app(True) appMenu = AppMenu(tool) menu, fileMenu, toolMenu, helpMenu = appMenu._draw_menu() self.assertTrue(menu.winfo_exists()) self.assertEqual(len(menu.winfo_children()), 2) self.assertEqual(menu.entrycget(1, 'label'), 'File') self.assertEqual(menu.entrycget(2, 'label'), 'Help') self.assertTrue(fileMenu.winfo_exists()) self.assertEqual(fileMenu.entrycget(1, 'label'), 'New Blank Project') self.assertEqual(fileMenu.entrycget(2, 'label'), 'New Project Wizard') self.assertEqual(fileMenu.entrycget(3, 'label'), 'Open Project') self.assertEqual(fileMenu.entrycget(5, 'label'), 'Quit') self.assertFalse(toolMenu) self.assertTrue(helpMenu.winfo_exists()) self.assertEqual(helpMenu.entrycget(1, 'label'), "OpenAnnotation Documentation") self.assertEqual(helpMenu.entrycget(2, 'label'), "About OpenAnnotation") tool.project_open = True tool.annotations = [] menu, fileMenu, toolMenu, helpMenu = appMenu._draw_menu() self.assertTrue(menu.winfo_exists()) self.assertEqual(len(menu.winfo_children()), 3) self.assertEqual(menu.entrycget(1, 'label'), 'File') self.assertEqual(menu.entrycget(2, 'label'), 'Tools') self.assertEqual(menu.entrycget(3, 'label'), 'Help') self.assertTrue(fileMenu.winfo_exists()) self.assertEqual(fileMenu.entrycget(1, 'label'), 'New Blank Project') self.assertEqual(fileMenu.entrycget(2, 'label'), 'New Project Wizard') self.assertEqual(fileMenu.entrycget(3, 'label'), 'Open Project') self.assertEqual(fileMenu.entrycget(4, 'label'), 'Save Project') self.assertEqual(fileMenu.entrycget(5, 'label'), 'Close Project') self.assertEqual(fileMenu.entrycget(7, 'label'), "Import File(s)") self.assertEqual(fileMenu.entrycget(8, 'label'), "Import Entire Directory") self.assertEqual(fileMenu.entrycget(9, 'label'), "Export Project to CSV") self.assertEqual(fileMenu.entrycget(11, 'label'), 'Quit') self.assertTrue(toolMenu.winfo_exists()) self.assertEqual(toolMenu.entrycget(1, 'label'), "Class Manager") self.assertEqual(toolMenu.entrycget(2, 'label'), 'Options') self.assertEqual(toolMenu.entrycget(3, 'label'), "Options") self.assertTrue(helpMenu.winfo_exists()) self.assertEqual(helpMenu.entrycget(1, 'label'), "OpenAnnotation Documentation") self.assertEqual(helpMenu.entrycget(2, 'label'), "About OpenAnnotation") tool.annotations.append(Annotation()) self.assertTrue(toolMenu.winfo_exists()) _, _, toolMenu, _ = appMenu._draw_menu() self.assertEqual(toolMenu.entrycget(1, 'label'), "Class Manager") self.assertEqual(toolMenu.entrycget(2, 'label'), 'Options') self.assertEqual(toolMenu.entrycget(3, 'label'), "Reset Image") self.assertEqual(toolMenu.entrycget(4, 'label'), 'Select Image #')