foolwood / SiamMask

[CVPR2019] Fast Online Object Tracking and Segmentation: A Unifying Approach
http://www.robots.ox.ac.uk/~qwang/SiamMask
MIT License
3.47k stars 819 forks source link

demo my own video?? #118

Open henbucuoshanghai opened 4 years ago

henbucuoshanghai commented 4 years ago

how to use it with my own video?

Marjanmoodi commented 4 years ago

You should pass your folder path to the demo.py as a parameter. For example, I put my images into the "my_test" folder under the "data" directory. So I can run the demo.py like this: python ../../tools/demo.py --base_path='../../data/my_test/images' --resume SiamMask_DAVIS.pth --config config_davis.json

henbucuoshanghai commented 4 years ago

I have to split the video to frames???and  30fps???

Marjanmoodi commented 4 years ago

Yes, you should split them.

henbucuoshanghai commented 4 years ago

the state of the art why cant i use it to the video directly??? and how to write the code?????

SArham commented 4 years ago

Code requires opencv for reading video. base_path now targets your desired video.

# Setup device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
torch.backends.cudnn.benchmark = True

# Setup Model
cfg = load_config(args)
from custom import Custom
siammask = Custom(anchors=cfg['anchors'])
if args.resume:
    assert isfile(args.resume), 'Please download {} first.'.format(args.resume)
    siammask = load_pretrain(siammask, args.resume)

siammask.eval().to(device)

# Parse Video file
video_path = args.base_path
video = cv2.VideoCapture(video_path)
ret, frame = video.read()
video.set(cv2.CAP_PROP_POS_FRAMES, 0)
# Select ROI
cv2.namedWindow("SiamMask", cv2.WND_PROP_FULLSCREEN)
# cv2.setWindowProperty("SiamMask", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
try:
    init_rect = cv2.selectROI('SiamMask', frame, False, False)
    x, y, w, h = init_rect
except:
    exit()

toc = 0
frame_number = 0
while video.isOpened():
    ret, im = video.read()
    tic = cv2.getTickCount()
    if not ret:
        break
    if frame_number == 0:  # init
        target_pos = np.array([x + w / 2, y + h / 2])
        target_sz = np.array([w, h])
        state = siamese_init(im, target_pos, target_sz, siammask, cfg['hp'], device=device)  # init tracker
    elif frame_number > 0:  # tracking
        state = siamese_track(state, im, mask_enable=True, refine_enable=True, device=device)  # track
        location = state['ploygon'].flatten()
        mask = state['mask'] > state['p'].seg_thr

        im[:, :, 2] = (mask > 0) * 255 + (mask == 0) * im[:, :, 2]
        cv2.polylines(im, [np.int0(location).reshape((-1, 1, 2))], True, (0, 255, 0), 3)
        cv2.imshow('SiamMask', im)
        key = cv2.waitKey(1)
        if key > 0:
            break
    frame_number += 1
    toc += cv2.getTickCount() - tic
toc /= cv2.getTickFrequency()
fps = frame_number / toc
print('SiamMask Time: {:02.1f}s Speed: {:3.1f}fps (with visulization!)'.format(toc, fps))
SamihaSara commented 4 years ago

I tried to run the demo.py with the idea provided in @Marjanmoodi's comment by inputting only 20 frames but got the following error. Please help what to do now.

image

this is the output i get image

henbucuoshanghai commented 4 years ago

the code is wrong???????

SamihaSara commented 4 years ago

Could you please explain why? I add nothing to the actual code just followed the instructions provided.

Marjanmoodi commented 4 years ago

@SamihaSara Did you run the command from this path: 'SiamMask/experiments/siammask_sharp' ?

SamihaSara commented 4 years ago

@Marjanmoodi yes I did run from this path still faced the error.

OnurSelim commented 3 years ago

@SArham Thank you for the video version. It helped a lot. :+1: