25
25
26
26
import multiprocessing
27
27
import os
28
+ import logging
28
29
29
30
import cv2
30
31
import exiftool
35
36
from skimage .transform import warp
36
37
from skimage .util import img_as_ubyte
37
38
39
+ logger = logging .getLogger (__name__ )
40
+
38
41
39
42
# start helper functions for finding a "hole"-free rectangle
40
43
def get_longest_sequence (b ):
@@ -206,7 +209,7 @@ def align(pair):
206
209
nol = pair ['pyramid_levels' ]
207
210
208
211
if pair ['debug' ]:
209
- print (( "number of pyramid levels: {}" . format ( nol )) )
212
+ logger . info ( "number of pyramid levels: %s" , nol )
210
213
211
214
warp_matrix [0 ][2 ] /= (2 ** nol )
212
215
warp_matrix [1 ][2 ] /= (2 ** nol )
@@ -244,7 +247,7 @@ def align(pair):
244
247
plotutils .plotwithcolorbar (gray2_pyr [level ], "match level {}" .format (level ))
245
248
plotutils .plotwithcolorbar (grad1 , "ref grad level {}" .format (level ))
246
249
plotutils .plotwithcolorbar (grad2 , "match grad level {}" .format (level ))
247
- print (("Starting warp for level {} is:\n {}" . format ( level , warp_matrix )) )
250
+ logger . info (("Starting warp for level %s is:\n %s" , level , warp_matrix )
248
251
249
252
try :
250
253
cc , warp_matrix = cv2 .findTransformECC (grad1 , grad2 , warp_matrix , warp_mode , criteria , inputMask = None ,
@@ -253,7 +256,7 @@ def align(pair):
253
256
cc , warp_matrix = cv2 .findTransformECC (grad1 , grad2 , warp_matrix , warp_mode , criteria )
254
257
255
258
if show_debug_images :
256
- print (( "Warp after alignment level {} is \n {}" . format ( level , warp_matrix )) )
259
+ logger . info ( "Warp after alignment level %s is \n %s" , level , warp_matrix )
257
260
258
261
if level != nol : # scale up only the offset by a factor of 2 for the next (larger image) pyramid level
259
262
if warp_mode == cv2 .MOTION_HOMOGRAPHY :
@@ -326,15 +329,15 @@ def align_capture(capture, ref_index=None, warp_mode=cv2.MOTION_HOMOGRAPHY, max_
326
329
pool = multiprocessing .Pool (processes = multiprocessing .cpu_count ())
327
330
for _ , mat in enumerate (pool .imap_unordered (align , alignment_pairs )):
328
331
warp_matrices [mat ['match_index' ]] = mat ['warp_matrix' ]
329
- print (( "Finished aligning band {}" . format ( mat ['match_index' ])) )
332
+ logger . info ( "Finished aligning band %s" , mat ['match_index' ])
330
333
pool .close ()
331
334
pool .join ()
332
335
else :
333
336
# Single-threaded alternative
334
337
for pair in alignment_pairs :
335
338
mat = align (pair )
336
339
warp_matrices [mat ['match_index' ]] = mat ['warp_matrix' ]
337
- print (("Finished aligning band {}" . format ( mat ['match_index' ])) )
340
+ logger . info (("Finished aligning band %s" , mat ['match_index' ])
338
341
339
342
if capture .images [- 1 ].band_name == 'LWIR' :
340
343
img = capture .images [- 1 ]
@@ -509,7 +512,7 @@ def min_max(pts):
509
512
510
513
def map_points (pts , image_size , warpMatrix , distortion_coeffs , camera_matrix , warp_mode = cv2 .MOTION_HOMOGRAPHY ):
511
514
# extra dimension makes opencv happy
512
- pts = np .array ([pts ], dtype = float )
515
+ pts = np .array ([pts ], dtype = np . float )
513
516
new_cam_mat , _ = cv2 .getOptimalNewCameraMatrix (camera_matrix , distortion_coeffs , image_size , 1 )
514
517
new_pts = cv2 .undistortPoints (pts , camera_matrix , distortion_coeffs , P = new_cam_mat )
515
518
if warp_mode == cv2 .MOTION_AFFINE :
@@ -588,7 +591,7 @@ def radiometric_pan_sharpen(capture, warp_matrices=None, panchro_band=5, irradia
588
591
# for comparison
589
592
# use the warp matrices we have for the stack, if not user supplied
590
593
if warp_matrices is None :
591
- print ("No SIFT warp matrices provided." )
594
+ logger . warning ("No SIFT warp matrices provided." )
592
595
warp_matrices = capture .get_warp_matrices (ref_index = panchro_band )
593
596
h , w = capture .images [panchro_band ].raw ().shape
594
597
if irradiance_list is None :
@@ -688,6 +691,8 @@ def write_exif_to_stack(thecapture=None, thefilename=None, existing_exif_list=No
688
691
raise Exception (
689
692
"Please provide an existing capture object and filename or a list of existing exif data for batch processing" )
690
693
exif_bytes_list = []
694
+ logger .debug ("EXIF_DATA %s" , exif_data )
695
+
691
696
for exif in exif_data :
692
697
for key , val in exif .items ():
693
698
if key != 'Capture ID' and key != 'Filename' :
0 commit comments