Prva druga check
parent
d400fb0a69
commit
175b970ed3
Binary file not shown.
After Width: | Height: | Size: 478 KiB |
Binary file not shown.
After Width: | Height: | Size: 282 KiB |
Binary file not shown.
After Width: | Height: | Size: 67 KiB |
Binary file not shown.
After Width: | Height: | Size: 53 KiB |
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue