5
5
import numpy as np
6
6
import cv2
7
7
import sys
8
+ import re
8
9
9
10
10
11
def run_match_pairs_script (folder ,relations_path ):
@@ -190,8 +191,11 @@ def panoramaBlending(dst_img_rz, src_img_warped, width_dst,smoothing_window):
190
191
191
192
# element-wise multiplication
192
193
dst_img_rz = dst_img_rz * mask2
194
+ cv2 .imwrite ("mask1.png" , mask1 * 255 )
193
195
src_img_warped = src_img_warped * mask1
194
-
196
+ cv2 .imwrite ("mask2.png" , mask2 * 255 )
197
+
198
+
195
199
# add two images
196
200
pano = src_img_warped + dst_img_rz
197
201
@@ -250,14 +254,18 @@ def crop(panorama, h_dst, conners):
250
254
251
255
return pano
252
256
253
-
257
+ def extract_number (filename ):
258
+ match = re .search (r'(\d+)' , filename )
259
+ return int (match .group ()) if match else 0
254
260
255
261
def main (args ):
256
262
257
263
output_file = 'image_names.txt'
258
264
os .makedirs (f"{ args .folder } /tmp" , exist_ok = True )
259
265
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
+
261
269
262
270
for i in range (len (images )- 1 ):
263
271
@@ -278,6 +286,24 @@ def main(args):
278
286
with open (f"image_names.txt" , 'w' ) as f :
279
287
f .write (f"{ images [i + 1 ]} { path_panorama .split ('/' )[- 1 ]} \n " )
280
288
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
+
281
307
# Run the match_pairs.py script
282
308
run_match_pairs_script (args .folder ,output_file )
283
309
0 commit comments