def test_get_match_coords(self): ''' Shall find matching coordinates ''' img1 = get_uint8_image(self.img1, self.imgMin, self.imgMax) img2 = get_uint8_image(self.img2, self.imgMin, self.imgMax) keyPoints1, descr1 = find_key_points(img1, nFeatures=self.nFeatures) keyPoints2, descr2 = find_key_points(img2, nFeatures=self.nFeatures) x1, y1, x2, y2 = get_match_coords(keyPoints1, descr1, keyPoints2, descr2) self.assertTrue(len(keyPoints1) > len(x1)) self.assertTrue(len(keyPoints2) > len(x2))
def test_lstsq_filter(self): ''' Shall filter out not matching points ''' img1 = get_uint8_image(self.img1, self.imgMin, self.imgMax) img2 = get_uint8_image(self.img2, self.imgMin, self.imgMax) keyPoints1, descr1 = find_key_points(img1, nFeatures=self.nFeatures) keyPoints2, descr2 = find_key_points(img2, nFeatures=self.nFeatures) x1, y1, x2, y2 = get_match_coords(keyPoints1, descr1, keyPoints2, descr2) x1f, y1f, x2f, y2f = lstsq_filter(x1, y1, x2, y2) self.assertTrue(len(x1) > len(x1f))
def test_max_drift_filter(self): '''Shall keep only slow drift ''' maxSpeed = 30 # km img1 = get_uint8_image(self.img1, self.imgMin, self.imgMax) img2 = get_uint8_image(self.img2, self.imgMin, self.imgMax) keyPoints1, descr1 = find_key_points(img1, nFeatures=self.nFeatures) keyPoints2, descr2 = find_key_points(img2, nFeatures=self.nFeatures) x1, y1, x2, y2 = get_match_coords(keyPoints1, descr1, keyPoints2, descr2) x1f, y1f, x2f, y2f = max_drift_filter(self.n1, x1, y1, self.n2, x2, y2) self.assertTrue(len(x1f) < len(x1))
def test_get_displacement_pix(self): ''' Shall find matching coordinates and plot quiver in pixel/line''' img1 = get_uint8_image(self.img1, self.imgMin, self.imgMax) img2 = get_uint8_image(self.img2, self.imgMin, self.imgMax) keyPoints1, descr1 = find_key_points(img1, nFeatures=self.nFeatures) keyPoints2, descr2 = find_key_points(img2, nFeatures=self.nFeatures) x1, y1, x2, y2 = get_match_coords(keyPoints1, descr1, keyPoints2, descr2) u, v = get_displacement_pix(self.n1, x1, y1, self.n2, x2, y2) plt.quiver(x1, y1, u, v) plt.savefig('sea_ice_drift_tests_02_quiver_pixlin.png') plt.close('all') self.assertTrue(len(u) == len(x1))
def test_get_displacement_km(self): ''' Shall find matching coordinates and plot quiver in lon/lat''' img1 = get_uint8_image(self.img1, self.imgMin, self.imgMax) img2 = get_uint8_image(self.img2, self.imgMin, self.imgMax) keyPoints1, descr1 = find_key_points(img1, nFeatures=self.nFeatures) keyPoints2, descr2 = find_key_points(img2, nFeatures=self.nFeatures) x1, y1, x2, y2 = get_match_coords(keyPoints1, descr1, keyPoints2, descr2) u, v = get_displacement_km(self.n1, x1, y1, self.n2, x2, y2) lon1, lat1 = self.n1.transform_points(x1, y1) plt.quiver(lon1, lat1, u, v) plt.savefig('sea_ice_drift_tests_01_quiver_lonlat.png') plt.close('all') self.assertTrue(len(u) == len(x1))
def test_domain_filter(self): ''' Shall leave keypoints from second image withn domain of the first ''' img1 = get_uint8_image(self.img1, self.imgMin, self.imgMax) img2 = get_uint8_image(self.img2, self.imgMin, self.imgMax) keyPoints1, descr1 = find_key_points(img1, nFeatures=self.nFeatures) keyPoints2, descr2 = find_key_points(img2, nFeatures=self.nFeatures) keyPoints2f, descr2f = domain_filter(self.n2, keyPoints2, descr2, self.n1, domainMargin=100) # plot dots cols1 = [kp.pt[0] for kp in keyPoints1] rows1 = [kp.pt[1] for kp in keyPoints1] lon1, lat1 = self.n1.transform_points(cols1, rows1, 0) cols2 = [kp.pt[0] for kp in keyPoints2f] rows2 = [kp.pt[1] for kp in keyPoints2f] lon2, lat2 = self.n2.transform_points(cols2, rows2, 0) plt.plot(lon1, lat1, '.') plt.plot(lon2, lat2, '.') plt.savefig('sea_ice_drift_tests_03_domain_filter.png') plt.close('all') self.assertTrue(len(descr2f) < len(descr2))
def test_find_key_points(self): ''' Shall find key points using default values ''' img1 = get_uint8_image(self.img1, self.imgMin, self.imgMax) keyPoints1, descr1 = find_key_points(img1) self.assertTrue(len(keyPoints1) > 1000)