def test_crop_shape(): from cvl.image_io import crop_patch from cvl.dataset import BoundingBox import numpy as np img = np.random.uniform(size=(1200, 600)) region = BoundingBox('tl-size', 50, 60, 100, 200) crop = crop_patch(img, region) assert crop.shape == region.shape()
def detect(self, image): # Convert to grayscale image = np.sum(image, 2) / 3 patch = self.crop_patch(image) patch = patch / 255 patch = patch - np.mean(patch) patch = patch / np.std(patch) patchf = fft2(patch) responsef = np.conj(self.template) * patchf response = ifft2(responsef) r, c = np.unravel_index(np.argmax(response), response.shape) # Keep for visualisation self.last_response = response r_offset = np.mod(r + self.region_center[0], self.region.height) - self.region_center[0] c_offset = np.mod(c + self.region_center[1], self.region.width) - self.region_center[1] self.region.xpos += c_offset self.region.ypos += r_offset # Revert update if bbox is completely out of image if self.region.intersection_box(BoundingBox("tl-size", 0, 0, image.shape[1], image.shape[0])).area() == 0.0: self.region.ypos -= r_offset self.region.xpos -= c_offset return self.region
def detect(self, image): """ Find the object's new position in image, using current model M """ # Convert to grayscale image = np.sum(image, 2) / 3 patch = crop_patch(image, self.region) P = fft2(MOSSETrackerGrayscale.normalize(patch)) response = ifft2( np.conjugate(self.M) * P ) r, c = np.unravel_index(np.argmax(response), response.shape) # Keep for visualisation self.last_response = response r_offset = np.mod(r + self.region_center[0], self.region.height) - self.region_center[0] c_offset = np.mod(c + self.region_center[1], self.region.width) - self.region_center[1] self.region.xpos += c_offset self.region.ypos += r_offset # Revert update if bbox is completely out of image if self.region.intersection_box(BoundingBox("tl-size", 0, 0, image.shape[1], image.shape[0])).area() == 0.0: self.region.ypos -= r_offset self.region.xpos -= c_offset return self.region
def test_crop_pad_value_negative(): from cvl.image_io import crop_patch from cvl.dataset import BoundingBox import numpy as np img = np.random.uniform(size=(1200, 600)) region = BoundingBox('tl-size', -1, 0, 100, 75) crop = crop_patch(img, region) assert crop[0, 0] == 0
def test_crop_region(): from cvl.image_io import crop_patch from cvl.dataset import BoundingBox import numpy as np img = np.random.uniform(size=(1200, 600)) region = BoundingBox('tl-size', 60, 50, 100, 200) crop = crop_patch(img, region) assert crop[0, 0] == img[region.ypos, region.xpos] assert crop[-1, -1] == img[region.ypos + region.height - 1, region.xpos + region.width - 1]
from cvl.dataset import OnlineTrackingBenchmark, BoundingBox from cvl.rgb_mosse import MultiMosseTracker SHOW_TRACKING = True if __name__ == "__main__": a_seq = {} j_x = 0 j_y = 0 for i in range(20): image = np.zeros((500, 500, 3)).astype('float32') image[j_x:40 + j_x, j_y:40 + j_y, :] = 1.0 a_seq[i] = { 'image': image, 'bounding_box': BoundingBox('tl-size', j_x - 20, j_y - 20, 80, 80) } j_x += 5 j_y += 5 for i in range(20, 40): image = np.zeros((500, 500, 3)).astype('float32') image[j_x:40 + j_x, j_y:40 + j_y, :] = 1.0 a_seq[i] = { 'image': image, 'bounding_box': BoundingBox('tl-size', j_x - 20, j_y - 20, 80, 80) } j_x -= 5 j_y += 5 for i in range(40, 60):