Skip to content

Commit b681ae9

Browse files
committed
some necessary fixes
1 parent 05f7ef0 commit b681ae9

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

stitching.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import cv2
77
import sys
8+
import re
89

910

1011
def run_match_pairs_script(folder,relations_path):
@@ -190,8 +191,11 @@ def panoramaBlending(dst_img_rz, src_img_warped, width_dst,smoothing_window):
190191

191192
# element-wise multiplication
192193
dst_img_rz = dst_img_rz * mask2
194+
cv2.imwrite("mask1.png", mask1 * 255)
193195
src_img_warped = src_img_warped * mask1
194-
196+
cv2.imwrite("mask2.png", mask2 * 255)
197+
198+
195199
# add two images
196200
pano = src_img_warped + dst_img_rz
197201

@@ -250,14 +254,18 @@ def crop(panorama, h_dst, conners):
250254

251255
return pano
252256

253-
257+
def extract_number(filename):
258+
match = re.search(r'(\d+)', filename)
259+
return int(match.group()) if match else 0
254260

255261
def main(args):
256262

257263
output_file = 'image_names.txt'
258264
os.makedirs(f"{args.folder}/tmp", exist_ok=True)
259265

260-
images = sorted([f for f in os.listdir(args.folder) if os.path.isfile(os.path.join(args.folder, f))])
266+
images = sorted([f for f in os.listdir(args.folder) if os.path.isfile(os.path.join(args.folder, f))], key=extract_number)
267+
print(images)
268+
261269

262270
for i in range(len(images)-1):
263271

@@ -278,6 +286,24 @@ def main(args):
278286
with open(f"image_names.txt", 'w') as f:
279287
f.write(f"{images[i+1]} {path_panorama.split('/')[-1]}\n")
280288

289+
# check if its neccesary to resize the images
290+
if i == 0:
291+
im1 = cv2.imread(f"{args.folder}/tmp/{images[i]}")
292+
else:
293+
im1 = cv2.imread(f"{args.folder}/tmp/{path_panorama.split('/')[-1]}")
294+
295+
im2 = cv2.imread(f"{args.folder}/tmp/{images[i+1]}")
296+
297+
if im1.shape[0] > 2000 or im1.shape[1] > 2000:
298+
im1 = cv2.resize(im1, (int(im1.shape[1]*0.5), int(im1.shape[0]*0.5)))
299+
cv2.imwrite(f"{args.folder}/tmp/{images[i]}", im1)
300+
cv2.imwrite(f"{args.folder}/{images[i]}", im1)
301+
302+
if im2.shape[0] > 2000 or im2.shape[1] > 2000:
303+
im2 = cv2.resize(im2, (int(im2.shape[1]*0.5), int(im2.shape[0]*0.5)))
304+
cv2.imwrite(f"{args.folder}/tmp/{images[i+1]}", im2)
305+
cv2.imwrite(f"{args.folder}/{images[i+1]}", im2)
306+
281307
# Run the match_pairs.py script
282308
run_match_pairs_script(args.folder ,output_file)
283309

0 commit comments

Comments
 (0)