-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (34 loc) · 1.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import cv2
import numpy as np
from matplotlib import pyplot as plt
import os
from scripts.panorama import stitch_images
if __name__ == "__main__":
# Load the images
# Use absolute paths for debugging purposes
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), './data'))
image1_path = os.path.join(root_dir, 'input', '1.jpg')
image2_path = os.path.join(root_dir, 'input', '2.jpg')
output_image_path = os.path.join(root_dir, 'output', 'panorama.jpg')
# Print the full paths for debugging
print(f"Image 1 path: {image1_path}")
print(f"Image 2 path: {image2_path}")
print(f"Output image path: {output_image_path}")
# Load the images
image1 = cv2.imread(image1_path)
image2 = cv2.imread(image2_path)
if image1 is None:
raise FileNotFoundError(f"Failed to load image: {image1_path}")
if image2 is None:
raise FileNotFoundError(f"Failed to load image: {image2_path}")
# Checking if images read
if image1 is None or image2 is None:
print("\nImages not read properly or does not exist.\n")
exit(0)
# Calling function for stitching images.
panorama = stitch_images(image1, image2)
# Saving the stitched image.
cv2.imwrite(output_image_path, panorama)
# Displaying the stitched images.
plt.imshow(panorama)
plt.show()