CSK icon indicating copy to clipboard operation
CSK copied to clipboard

How to run it with my own video

Open KyGao opened this issue 5 years ago • 0 comments

Hello, I am new to visual tracking. Your code is the clearest implementation I have found. I tried to add my PC camera to track, but it seems that the bounding box is not able to move. I pastes my test code here. Thanks a lot if someone would help me!

import csk
import numpy as np
from scipy.misc import imread, imsave
import cv2 # (Optional) OpenCV for drawing bounding boxes

length = 14 # sequence length

# 1st frame's groundtruth information
x1 = 325 # position x of the top-left corner of bounding box
y1 = 162 # position y of the top-left corner of bounding box
width = 74 # the width of bounding box
height = 80 # the height of bounding box

sequence_path = "data/" # your sequence path
save_path = "save/" # your save path

tracker = csk.CSK() # CSK instance

cap=cv2.VideoCapture(0)
flag = True

while True:
    ret, img=cap.read()
    frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
    if flag:
        tracker.init(frame,x1,y1,width,height) # initialize CSK tracker with GT bounding box
        flag = False
        cv2.rectangle(img, (x1, y1), (x1+width, y1+height), (0,255,0), 2)
        cv2.imshow("original", img)
    else:
        x1, y1 = tracker.update(frame) # update CSK tracker and output estimated position
        cv2.rectangle(img, (x1, y1), (x1+width, y1+height), (0,255,0), 2)
        cv2.imshow("frame", img)
    
    k=cv2.waitKey(30) & 0xFF
    if k==32:
        break

# clean up the camera and close any open windows
cap.release()
cv2.destroyAllWindows()

KyGao avatar Apr 26 '20 16:04 KyGao