

def camshiftTracker(img, bb, ts, **kwargs):
    "\n    **DESCRIPTION**\n    \n    (Dev Zone)\n\n    Tracking the object surrounded by the bounding box in the given\n    image using CAMshift method.\n\n    Warning: Use this if you know what you are doing. Better have a \n    look at Image.track()\n\n    **PARAMETERS**\n\n    * *img* - Image - Image to be tracked.\n    * *bb*  - tuple - Bounding Box tuple (x, y, w, h)\n    * *ts*  - TrackSet - SimpleCV.Features.TrackSet.\n\n    Optional PARAMETERS:\n\n    lower      - Lower HSV value for inRange thresholding\n                 tuple of (H, S, V)\n                \n    upper      - Upper HSV value for inRange thresholding\n                 tuple of (H, S, V)\n\n    mask       - Mask to calculate Histogram. It's better \n                 if you don't provide one.\n\n    num_frames - number of frames to be backtracked.\n\n    **RETURNS**\n\n    SimpleCV.Features.Tracking.CAMShift\n\n    **HOW TO USE**\n\n    >>> cam = Camera()\n    >>> ts = []\n    >>> img = cam.getImage()\n    >>> bb = (100, 100, 300, 300) # get BB from somewhere\n    >>> ts = CAMShiftTracker(img, bb, ts, lower=(40, 120, 120), upper=(80, 200, 200), num_frames=30)\n    >>> while (some_condition_here):\n        ... img = cam.getImage()\n        ... bb = ts[-1].bb\n        ... ts = CAMShiftTracker(img, bb, ts, lower=(40, 120, 120), upper=(80, 200, 200), num_frames=30)\n        ... ts[-1].drawBB()\n        ... img.show()\n\n    This is too much confusing. Better use\n    Image.track() method.\n\n    READ MORE:\n\n    CAMShift Tracker:\n    Uses meanshift based CAMShift thresholding technique. Blobs and objects with\n    single tone or tracked very efficiently. CAMshift should be preferred if you \n    are trying to track faces. It is optimized to track faces.\n    "
    lower = np.array((0.0, 60.0, 32.0))
    upper = np.array((180.0, 255.0, 255.0))
    mask = None
    num_frames = 40
    if (not isinstance(bb, tuple)):
        bb = tuple(bb)
    bb = (int(bb[0]), int(bb[1]), int(bb[2]), int(bb[3]))
    for key in kwargs:
        if (key == 'lower'):
            lower = np.array(tuple(kwargs[key]))
        elif (key == 'upper'):
            upper = np.array(tuple(kwargs[key]))
        elif (key == 'mask'):
            mask = kwargs[key]
            mask = mask.getNumpyCv2()
        elif (key == 'num_frames'):
            num_frames = kwargs[key]
    hsv = cv2.cvtColor(img.getNumpyCv2(), cv2.cv.CV_BGR2HSV)
    if (mask is None):
        mask = cv2.inRange(hsv, lower, upper)
    (x0, y0, w, h) = bb
    x1 = ((x0 + w) - 1)
    y1 = ((y0 + h) - 1)
    hsv_roi = hsv[y0:y1, x0:x1]
    mask_roi = mask[y0:y1, x0:x1]
    hist = cv2.calcHist([hsv_roi], [0], mask_roi, [16], [0, 180])
    cv2.normalize(hist, hist, 0, 255, cv2.NORM_MINMAX)
    hist_flat = hist.reshape((- 1))
    imgs = [hsv]
    if ((len(ts) > num_frames) and (num_frames > 1)):
        for feat in ts[(- num_frames):]:
            imgs.append(feat.image.toHSV().getNumpyCv2())
    elif ((len(ts) < num_frames) and (num_frames > 1)):
        for feat in ts:
            imgs.append(feat.image.toHSV().getNumpyCv2())
    prob = cv2.calcBackProject(imgs, [0], hist_flat, [0, 180], 1)
    prob &= mask
    term_crit = ((cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT), 10, 1)
    (new_ellipse, track_window) = cv2.CamShift(prob, bb, term_crit)
    if ((track_window[2] == 0) or (track_window[3] == 0)):
        track_window = bb
    track = CAMShiftTrack(img, track_window, new_ellipse)
    return track

dataset/ETHPy150Open sightmachine/SimpleCV/SimpleCV/Tracking/CAMShiftTracker.py camshiftTracker/original