2525
2626import multiprocessing
2727import os
28+ import logging
2829
2930import cv2
3031import exiftool
3536from skimage .transform import warp
3637from skimage .util import img_as_ubyte
3738
39+ logger = logging .getLogger (__name__ )
40+
3841
3942# start helper functions for finding a "hole"-free rectangle
4043def get_longest_sequence (b ):
@@ -206,7 +209,7 @@ def align(pair):
206209 nol = pair ['pyramid_levels' ]
207210
208211 if pair ['debug' ]:
209- print (( "number of pyramid levels: {}" . format ( nol )) )
212+ logger . info ( "number of pyramid levels: %s" , nol )
210213
211214 warp_matrix [0 ][2 ] /= (2 ** nol )
212215 warp_matrix [1 ][2 ] /= (2 ** nol )
@@ -244,7 +247,7 @@ def align(pair):
244247 plotutils .plotwithcolorbar (gray2_pyr [level ], "match level {}" .format (level ))
245248 plotutils .plotwithcolorbar (grad1 , "ref grad level {}" .format (level ))
246249 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 )
248251
249252 try :
250253 cc , warp_matrix = cv2 .findTransformECC (grad1 , grad2 , warp_matrix , warp_mode , criteria , inputMask = None ,
@@ -253,7 +256,7 @@ def align(pair):
253256 cc , warp_matrix = cv2 .findTransformECC (grad1 , grad2 , warp_matrix , warp_mode , criteria )
254257
255258 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 )
257260
258261 if level != nol : # scale up only the offset by a factor of 2 for the next (larger image) pyramid level
259262 if warp_mode == cv2 .MOTION_HOMOGRAPHY :
@@ -326,15 +329,15 @@ def align_capture(capture, ref_index=None, warp_mode=cv2.MOTION_HOMOGRAPHY, max_
326329 pool = multiprocessing .Pool (processes = multiprocessing .cpu_count ())
327330 for _ , mat in enumerate (pool .imap_unordered (align , alignment_pairs )):
328331 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' ])
330333 pool .close ()
331334 pool .join ()
332335 else :
333336 # Single-threaded alternative
334337 for pair in alignment_pairs :
335338 mat = align (pair )
336339 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' ])
338341
339342 if capture .images [- 1 ].band_name == 'LWIR' :
340343 img = capture .images [- 1 ]
@@ -509,7 +512,7 @@ def min_max(pts):
509512
510513def map_points (pts , image_size , warpMatrix , distortion_coeffs , camera_matrix , warp_mode = cv2 .MOTION_HOMOGRAPHY ):
511514 # extra dimension makes opencv happy
512- pts = np .array ([pts ], dtype = float )
515+ pts = np .array ([pts ], dtype = np . float )
513516 new_cam_mat , _ = cv2 .getOptimalNewCameraMatrix (camera_matrix , distortion_coeffs , image_size , 1 )
514517 new_pts = cv2 .undistortPoints (pts , camera_matrix , distortion_coeffs , P = new_cam_mat )
515518 if warp_mode == cv2 .MOTION_AFFINE :
@@ -588,7 +591,7 @@ def radiometric_pan_sharpen(capture, warp_matrices=None, panchro_band=5, irradia
588591 # for comparison
589592 # use the warp matrices we have for the stack, if not user supplied
590593 if warp_matrices is None :
591- print ("No SIFT warp matrices provided." )
594+ logger . warning ("No SIFT warp matrices provided." )
592595 warp_matrices = capture .get_warp_matrices (ref_index = panchro_band )
593596 h , w = capture .images [panchro_band ].raw ().shape
594597 if irradiance_list is None :
@@ -688,6 +691,8 @@ def write_exif_to_stack(thecapture=None, thefilename=None, existing_exif_list=No
688691 raise Exception (
689692 "Please provide an existing capture object and filename or a list of existing exif data for batch processing" )
690693 exif_bytes_list = []
694+ logger .debug ("EXIF_DATA %s" , exif_data )
695+
691696 for exif in exif_data :
692697 for key , val in exif .items ():
693698 if key != 'Capture ID' and key != 'Filename' :
0 commit comments