diff --git a/assignment4/datam/dining_room_keypoints.png b/assignment4/datam/dining_room_keypoints.png new file mode 100644 index 0000000..17fd33e Binary files /dev/null and b/assignment4/datam/dining_room_keypoints.png differ diff --git a/assignment4/datam/dining_room_rotated.png b/assignment4/datam/dining_room_rotated.png new file mode 100644 index 0000000..2acb585 Binary files /dev/null and b/assignment4/datam/dining_room_rotated.png differ diff --git a/assignment4/datam/frames/0.jpg b/assignment4/datam/frames/0.jpg new file mode 100644 index 0000000..9229c50 Binary files /dev/null and b/assignment4/datam/frames/0.jpg differ diff --git a/assignment4/datam/frames/1.jpg b/assignment4/datam/frames/1.jpg new file mode 100644 index 0000000..23e53df Binary files /dev/null and b/assignment4/datam/frames/1.jpg differ diff --git a/assignment4/solution.py b/assignment4/solution.py index 2267d3c..896e7dd 100644 --- a/assignment4/solution.py +++ b/assignment4/solution.py @@ -54,7 +54,7 @@ def one_b() -> None: def ex2(): two_a() - #two_b() + two_b() def two_a() -> None: """ @@ -74,20 +74,15 @@ def two_a() -> None: # Find the correspondences matches_a = uz_image.find_correspondences(graph_a_descriptors, graph_b_descriptors) matches_b = uz_image.find_correspondences(graph_b_descriptors, graph_a_descriptors) - + matches_a_coordinates = [] - matche_b_coordinates = [] + matches_b_coordinates = [] for i, match in enumerate(matches_a): - if i % 2 == 0: # plot every second one - if np.flip(match) in matches_b: # Check if the match is reciprocal - print(np.argwhere(matches_b == np.flip(match))) - matches_a_coordinates.append(np.flip(graph_a_keypoints[match[0]])) - matche_b_coordinates.append(np.flip(graph_b_keypoints[match[1]])) - else: - print("Not reciprocal") + matches_a_coordinates.append(np.flip(graph_a_keypoints[match[0]])) + matches_b_coordinates.append(np.flip(graph_b_keypoints[match[1]])) # Plot the matches - uz_image.display_matches(graph_a_small, matches_a_coordinates, graph_b_small, matche_b_coordinates) + uz_image.display_matches(graph_a_small, matches_a_coordinates, graph_b_small, matches_b_coordinates) def two_b() -> None: """ @@ -157,10 +152,10 @@ def three_b() -> None: """ Hi """ - image_a = uz_image.imread_gray("data/graf/graf_a.jpg", uz_image.ImageType.float64) - image_b = uz_image.imread_gray("data/graf/graf_b.jpg", uz_image.ImageType.float64) - #image_a = uz_image.imread_gray("datam/img1.jpg", uz_image.ImageType.float64) - #image_b = uz_image.imread_gray("datam/img2.jpg", uz_image.ImageType.float64) + #image_a = uz_image.imread_gray("data/graf/graf_a.jpg", uz_image.ImageType.float64) + #image_b = uz_image.imread_gray("data/graf/graf_b.jpg", uz_image.ImageType.float64) + image_a = uz_image.imread_gray("datam/img1.jpg", uz_image.ImageType.float64) + image_b = uz_image.imread_gray("datam/img2.jpg", uz_image.ImageType.float64) #image_a = uz_image.imread_gray("data/newyork/newyork_a.jpg", uz_image.ImageType.float64) #image_b = uz_image.imread_gray("data/newyork/newyork_b.jpg", uz_image.ImageType.float64) # Does not work for newyork dataset, becouse the keypoints are not reciprocal @@ -182,8 +177,17 @@ def three_b() -> None: return np.array(a_points), np.array(b_points) a,b = map_keypoints(best_inliers) + uz_image.display_matches(image_a, a, image_b, b) + img_output = cv2.warpPerspective(image_a, hm, (image_b.shape[1], image_b.shape[0])) + + fig, axs = plt.subplots(1, 2) + fig.suptitle("Transformation and rotation using homography") + axs[0].imshow(image_b, cmap="gray") + axs[1].imshow(img_output, cmap="gray") + plt.show() + def three_lol(): """ Hi @@ -209,8 +213,8 @@ def three_lol(): def main(): #ex1() - #ex2() - ex3() + ex2() + #ex3() if __name__ == '__main__': main() diff --git a/assignment4/uz_framework/__init__.py b/assignment4/uz_framework/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/assignment4/uz_framework/image.py b/assignment4/uz_framework/image.py index 6c5c8f9..72d60e2 100644 --- a/assignment4/uz_framework/image.py +++ b/assignment4/uz_framework/image.py @@ -1186,7 +1186,7 @@ def estimate_homography(keypoints: npt.NDArray[np.float64]) \ def ransac(image_a: npt.NDArray[np.float64], correspondences_a: npt.NDArray[np.float64], image_b: npt.NDArray[np.float64], correspondences_b: npt.NDArray[np.float64], - iterations: int = 1000, + iterations: int = 5000, threshold: float = 3) \ -> tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]: """ @@ -1207,7 +1207,7 @@ def ransac(image_a: npt.NDArray[np.float64], correspondences_a: npt.NDArray[np.f # Make it (x,y) -> (x,y) = x,y,x,y matrix keypoints = np.concatenate((sample_a, sample_b), axis=1) # Estimate homography - homography = estimate_homography(image_a, image_b, keypoints) + homography = estimate_homography(keypoints) # Compute the inliers inlier_indices = [] # Calculate the distance between the transformed points and the actual points