class StruckTracker(GenericVisionTracker): """ TODO """ def __init__(self): """ Initialize the tracker """ self.name = 'struck_tracker' f = open("config.txt", "w") f.write(struck_config) f.close() self.reset() def reset(self): """ Reset the tracker :return: """ self._primed = False self.bbox = None def _prime(self, im, bounding_region): """ prime tracker on image and bounding box :param im: input image (3 - channel numpy array) :type im: numpy.ndarray :param bounding_region: initial bounding region of the tracked object :type bounding_region: PVM_tools.bounding_region.BoundingRegion """ self.bbox=bounding_region bounding_box = bounding_region.get_box_pixels() struck.STRUCK_init(im, bounding_box) def _track(self, im): """ Track on given image, return a bounding box :param im: image (3 - channel numpy array) :type im: numpy.ndarray :return: bounding box of the tracker object :rtype: PVM_tools.bounding_region.BoundingRegion """ # this is required so that tracker is re-initialized if it is primed again self._primed = False struck.STRUCK_track(im) struck_bbox = struck.STRUCK_get_bbox() self.bounding_box = [struck_bbox["xmin"], struck_bbox["ymin"], struck_bbox["width"], struck_bbox["height"]] if self.bounding_box == (): self.bbox = BoundingRegion() else: self.bbox = BoundingRegion(image_shape=(im.shape[0], im.shape[1], 3), box=self.bounding_box) return self.bbox.copy() def get_heatmap(self, heatmap_name=None): return self.bbox.get_mask()
class CenterVisionTracker(GenericVisionTracker): """ This class exposes the null vision tracker which just always returns its priming bounding box """ def __init__(self, size_factor=0.2, new_name=None): """ Initialize the tracker """ if new_name is None: self.name = 'center_tracker' else: self.name = new_name self.size_factor = size_factor def reset(self): """ Reset the tracker :return: """ self._primed = False self.bbox = None def _prime(self, im, bounding_region): """ prime tracker on image and bounding box :param im: input image (3 - channel numpy array) :type im: numpy.ndarray :param bounding_region: initial bounding region of the tracked object :type bounding_region: PVM_tools.bounding_region.BoundingRegion """ box = np.array([(im.shape[1] - im.shape[1] * self.size_factor) / 2, (im.shape[0] - im.shape[0] * self.size_factor) / 2, im.shape[1] * self.size_factor, im.shape[0] * self.size_factor]).astype(np.int) self.bbox = BoundingRegion(image_shape=im.shape, box=box) if not self._primed: self._primed = True def _track(self, im): """ Track on given image, rseturn a bounding box :param im: image (3 - channel numpy array) :type im: numpy.ndarray :return: bounding box of the tracker object :rtype: PVM_tools.bounding_region.BoundingRegion """ # this is required so that tracker is re-initialized if it is primed again self._primed = False return self.bbox.copy() def get_heatmap(self, heatmap_name=None): return self.bbox.get_mask()
class CenterVisionTracker(GenericVisionTracker): """ This class exposes the null vision tracker which just always returns its priming bounding box """ def __init__(self, size_factor=0.2, new_name=None): """ Initialize the tracker """ if new_name is None: self.name = 'center_tracker' else: self.name = new_name self.size_factor = size_factor def reset(self): """ Reset the tracker :return: """ self._primed = False self.bbox = None def _prime(self, im, bounding_region): """ prime tracker on image and bounding box :param im: input image (3 - channel numpy array) :type im: numpy.ndarray :param bounding_region: initial bounding region of the tracked object :type bounding_region: PVM_tools.bounding_region.BoundingRegion """ box = np.array([(im.shape[1]-im.shape[1]*self.size_factor)/2, (im.shape[0]-im.shape[0]*self.size_factor)/2, im.shape[1]*self.size_factor, im.shape[0]*self.size_factor]).astype(np.int) self.bbox = BoundingRegion(image_shape=im.shape, box=box) if not self._primed: self._primed = True def _track(self, im): """ Track on given image, rseturn a bounding box :param im: image (3 - channel numpy array) :type im: numpy.ndarray :return: bounding box of the tracker object :rtype: PVM_tools.bounding_region.BoundingRegion """ # this is required so that tracker is re-initialized if it is primed again self._primed = False return self.bbox.copy() def get_heatmap(self, heatmap_name=None): return self.bbox.get_mask()
class TLDVisionTracker(GenericVisionTracker): """ This class exposes the open tld tracker implemented in C++ by http://www.gnebehay.com/tld/. Originally OpenTLD that was originally published in MATLAB by Zdenek Kalal. """ def __init__(self): """ Initialize the tracker """ self.name = 'tld_tracker' self.reset() def reset(self): """ Reset the tracker :return: """ self.tld = None self._primed = False self.bbox = None def _prime(self, im, bounding_region): """ prime tracker on image and bounding box :param im: input image (3 - channel numpy array) :type im: numpy.ndarray :param bounding_region: initial bounding region of the tracked object :type bounding_region: PVM_tools.bounding_region.BoundingRegion """ self.bbox = bounding_region bounding_box = bounding_region.get_box_pixels() if not self._primed: self.tld = tld.TLD2() self._primed = True self.height, self.width = im.shape[:2] self.tld.set_width_and_height((self.width, self.height)) im = cv2.cvtColor(im, cv2.COLOR_RGB2GRAY) img_cvmat = cv2.cv.fromarray(im) if bounding_box[0] + bounding_box[2] > self.width: bounding_box[2] = self.width - bounding_box[0] if bounding_box[1] + bounding_box[3] > self.height: bounding_box[3] = self.height - bounding_box[1] self.tld.selectObject( img_cvmat, tuple([ int(bounding_box[0]), int(bounding_box[1]), int(bounding_box[2]), int(bounding_box[3]) ])) def _track(self, im): """ Track on given image, return a bounding box :param im: image (3 - channel numpy array) :type im: numpy.ndarray :return: bounding box of the tracker object :rtype: PVM_tools.bounding_region.BoundingRegion """ # this is required so that tracker is re-initialized if it is primed again self._primed = False img_cvmat = cv2.cv.fromarray(im) self.tld.processImage(img_cvmat) self.bounding_box = self.tld.getCurrBB() self.confidence = self.tld.currConf if self.bounding_box == (): self.bbox = BoundingRegion() else: self.bbox = BoundingRegion(image_shape=(im.shape[0], im.shape[1], 3), box=self.bounding_box, confidence=self.confidence) return self.bbox.copy() def get_heatmap(self, heatmap_name=None): return self.bbox.get_mask()
class CMTVisionTracker(GenericVisionTracker): """ This class exposes the CMT tracker implemented in http://www.gnebehay.com/CMT/. """ def __init__(self): """ Initialize the tracker """ self.name = 'cmt_tracker' self.reset() def reset(self): """ Reset the tracker :return: """ self.cmt = None self._primed = False self.bbox = None def _prime(self, im, bounding_region): """ prime tracker on image and bounding box :param im: input image (3 - channel numpy array) :type im: numpy.ndarray :param bounding_region: initial bounding region of the tracked object :type bounding_region: PVM_tools.bounding_region.BoundingRegion """ self.bbox=bounding_region bounding_box = bounding_region.get_box_pixels() if not self._primed: this_dir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(this_dir+"/original_cmt/") from CMT import CMT self.cmt = CMT() self._primed = True self.height, self.width = im.shape[:2] im = cv2.cvtColor(im, cv2.COLOR_RGB2GRAY) self.cmt.initialise(im_gray0=im, tl=tuple([bounding_box[0], bounding_box[1]]), br=tuple([bounding_box[0]+bounding_box[2], bounding_box[1]+bounding_box[3]])) self.im_prev = im def _track(self, im): """ Track on given image, return a bounding box :param im: image (3 - channel numpy array) :type im: numpy.ndarray :return: bounding box of the tracker object :rtype: PVM_tools.bounding_region.BoundingRegion """ # this is required so that tracker is re-initialized if it is primed again self._primed = False self.im_prev = im im = cv2.cvtColor(im, cv2.COLOR_RGB2GRAY) self.cmt.process_frame(im) self.confidence = 1 if np.isnan(self.cmt.bb).any(): self.bbox = BoundingRegion() else: self.bbox = BoundingRegion(image_shape=im.shape, box=self.cmt.bb, confidence=self.confidence) return self.bbox.copy() def get_heatmap(self, heatmap_name=None): return self.bbox.get_mask()
class StruckTracker(GenericVisionTracker): """ TODO """ def __init__(self): """ Initialize the tracker """ self.name = 'struck_tracker' f = open("config.txt", "w") f.write(struck_config) f.close() self.reset() def reset(self): """ Reset the tracker :return: """ self._primed = False self.bbox = None def _prime(self, im, bounding_region): """ prime tracker on image and bounding box :param im: input image (3 - channel numpy array) :type im: numpy.ndarray :param bounding_region: initial bounding region of the tracked object :type bounding_region: PVM_tools.bounding_region.BoundingRegion """ self.bbox = bounding_region bounding_box = bounding_region.get_box_pixels() struck.STRUCK_init(im, bounding_box) def _track(self, im): """ Track on given image, return a bounding box :param im: image (3 - channel numpy array) :type im: numpy.ndarray :return: bounding box of the tracker object :rtype: PVM_tools.bounding_region.BoundingRegion """ # this is required so that tracker is re-initialized if it is primed again self._primed = False struck.STRUCK_track(im) struck_bbox = struck.STRUCK_get_bbox() self.bounding_box = [ struck_bbox["xmin"], struck_bbox["ymin"], struck_bbox["width"], struck_bbox["height"] ] if self.bounding_box == (): self.bbox = BoundingRegion() else: self.bbox = BoundingRegion(image_shape=(im.shape[0], im.shape[1], 3), box=self.bounding_box) return self.bbox.copy() def get_heatmap(self, heatmap_name=None): return self.bbox.get_mask()
class TLDVisionTracker(GenericVisionTracker): """ This class exposes the open tld tracker implemented in C++ by http://www.gnebehay.com/tld/. Originally OpenTLD that was originally published in MATLAB by Zdenek Kalal. """ def __init__(self): """ Initialize the tracker """ self.name = 'tld_tracker' self.reset() def reset(self): """ Reset the tracker :return: """ self.tld = None self._primed = False self.bbox = None def _prime(self, im, bounding_region): """ prime tracker on image and bounding box :param im: input image (3 - channel numpy array) :type im: numpy.ndarray :param bounding_region: initial bounding region of the tracked object :type bounding_region: PVM_tools.bounding_region.BoundingRegion """ self.bbox=bounding_region bounding_box = bounding_region.get_box_pixels() if not self._primed: self.tld = tld.TLD2() self._primed = True self.height, self.width = im.shape[:2] self.tld.set_width_and_height((self.width, self.height)) im = cv2.cvtColor(im, cv2.COLOR_RGB2GRAY) img_cvmat = cv2.cv.fromarray(im) if bounding_box[0] + bounding_box[2] > self.width: bounding_box[2] = self.width - bounding_box[0] if bounding_box[1] + bounding_box[3] > self.height: bounding_box[3] = self.height - bounding_box[1] self.tld.selectObject(img_cvmat, tuple([int(bounding_box[0]), int(bounding_box[1]), int(bounding_box[2]), int(bounding_box[3])])) def _track(self, im): """ Track on given image, return a bounding box :param im: image (3 - channel numpy array) :type im: numpy.ndarray :return: bounding box of the tracker object :rtype: PVM_tools.bounding_region.BoundingRegion """ # this is required so that tracker is re-initialized if it is primed again self._primed = False img_cvmat = cv2.cv.fromarray(im) self.tld.processImage(img_cvmat) self.bounding_box = self.tld.getCurrBB() self.confidence = self.tld.currConf if self.bounding_box == (): self.bbox = BoundingRegion() else: self.bbox = BoundingRegion(image_shape=(im.shape[0], im.shape[1], 3), box=self.bounding_box, confidence=self.confidence) return self.bbox.copy() def get_heatmap(self, heatmap_name=None): return self.bbox.get_mask()