def convert_region(region: Region) -> TraxRegion: if isinstance(region, Rectangle): return TraxRectangle.create(region.x, region.y, region.width, region.height) elif isinstance(region, Polygon): return TraxPolygon.create(region.points) elif isinstance(region, Mask): return TraxMask.create(region.mask, x=region.offset[0], y=region.offset[1]) return None
def test_convert_traxregion(self): convert_traxregion(TraxRectangle.create(0, 0, 10, 10)) convert_traxregion( TraxPolygon.create([(0, 0), (10, 0), (10, 10), (0, 10)])) convert_traxregion(TraxMask.create(np.ones((100, 100), dtype=np.uint8)))
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) tracking_module_path = os.path.join(os.path.dirname(os.path.join(os.path.realpath(__file__))), '../tracking') eprint('Loading tracker from', tracking_module_path) sys.path.insert(0, tracking_module_path) from tracker import Tracker handle = vot.VOT("rectangle") selection = handle.region() # Process the first frame imagefile = handle.frame() if not imagefile: sys.exit(0) first_frame = Image.open(imagefile).convert('RGB') mdnet = Tracker((selection.x, selection.y, selection.width, selection.height), first_frame) while True: imagefile = handle.frame() if not imagefile: break frame = Image.open(imagefile).convert('RGB') pred_bbox, confidence = mdnet.track(frame) handle.report(Rectangle(pred_bbox[0], pred_bbox[1], pred_bbox[2], pred_bbox[3]), confidence)