def test(): from sift import SIFT from skimage.io import imread, imsave import loader import matplotlib.pyplot as plt # img = 5*np.ones((50,40)) # img[:25,:25] = 20. # img = imread('./examples/jinco2.jpg') # load jinco # data = './data/ykdelB_26906_19066' # data = './data/Haywrd_15302_19031' # testloader = loader.setup_testloader(data, args) # dataset = testloader.dataset # # print('num train data:', len(dataset)) # ndataset = len(dataset) # img = dataset.get_image(20) # imsave('./examples/Haywrd_15302_19031_example.png', img) img = imread('./examples/Haywrd_15302_19031_example.png') # load jinco # print('image shape', img.shape) desc, kp = detect_and_extract(img, Mmax=4, threshold=5., duplicate=False) sift_detector = SIFT(img, num_octave=8) kp_sift, desc_sift = sift_detector.compute() f, ax = plt.subplots(1, 2, figsize=(15, 15)) ax[0].imshow(img) ax[0].scatter(kp[:, 0], kp[:, 1], c='r', s=2.5) ax[0].axis('off') ax[1].imshow(img) ax[1].scatter(kp_sift[:, 0], kp_sift[:, 1], c='r', s=2.5) ax[1].axis('off') plt.show()
video_writer = imageio.get_writer(video_name, fps=15) # Exit if video not opened. if not video.isOpened(): print "Could not open video" sys.exit() # Read first frame. ok, frame = video.read() if not ok: print 'Cannot read video file' sys.exit() # Use SIFT find init_bbox if init_bbox is none if init_bbox is None: pt = sift.compute(frame) # Stop if both methods failed if pt is None: raise ValueError("Initial Tracking Failed!!!") init_bbox = sift.getBoxFromPt(pt, DEFAULT_BBOX) # Initialize tracker with first frame and bounding box print "image {} / {}, bbox: {}".format(video.getFrameIdx(), frame_num, init_bbox) ok = tracker.init(frame, init_bbox) # Draw initial bbox frame = drawBox(frame, init_bbox) # Crop patch and analysis using histogram prevHist = cropImageAndHistogram(frame, init_bbox, HOG)