Example #1
0
import cv2
from FeatureHaar import*
from Boosting import*

video = cv2.VideoCapture('OpenCV-Trackers/assets/chaplin.mp4')

ret, frame = video.read()
roi = cv2.selectROI(frame)
frame = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
roi_ls = [roi[0],roi[1],roi[0]+roi[2],roi[1]+roi[3]]
tracker = Boosting(frame,roi_ls,150,12500,50,2)
tracker.get_search_region()
tracker.set_ii_searchregion()
tracker.build_features()
tracker.init_selector_pool()
tracker.train_weak_classifier()
tracker.get_strong_classifier()

while(video.isOpened()):
    ret, frame = video.read()

    frame = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
    tracker.update_frame(frame)
    tracker.get_confidence_map()
    new_roi = tracker.get_meanshift_bbox()
    tracker.update_roi(new_roi)
    tracker.get_search_region()
    cv2.rectangle(frame,(new_roi[0],new_roi[1]),(new_roi[2],new_roi[3]),(0,255,0),2)
    cv2.imshow('frame',frame)

    k = cv2.waitKey(1) & 0xff
Example #2
0
# img_ii = integral_image(img)
# print(img_ii)
# roi = [1,1,4,4]
# bo = Boosting(img,roi,10,30,6,2)
# bo.get_search_region()
# bo.set_ii_searchregion()
# bo.build_features()
# bo.init_selector_pool()
# bo.train_weak_classifier()

img_org = cv2.imread("./assets/edge-detection.png")
roi = cv2.selectROI(img_org)
print(roi)
img = cv2.cvtColor(img_org, cv2.COLOR_RGB2GRAY)
roi_image = img[roi[1]:roi[1] + roi[3], roi[0]:roi[0] + roi[2]]
cv2.imshow("roiImage", roi_image)
roi_ls = [roi[0], roi[1], roi[0] + roi[2], roi[1] + roi[3]]
bo = Boosting(img, roi_ls, 150, 12500, 50, 2)
bo.get_search_region()
bo.set_ii_searchregion()
bo.build_features()
bo.init_selector_pool()
bo.train_weak_classifier()
bo.get_strong_classifier()
bo.get_confidence_map()
new_roi = bo.get_meanshift_bbox()
#new_roi = bo.get_bbox()
cv2.rectangle(img_org, (new_roi[0], new_roi[1]), (new_roi[2], new_roi[3]),
              (0, 255, 0), 2)
cv2.imshow('newroi', img_org)
cv2.waitKey(0)