@@ -18,25 +18,34 @@ def __init__(self, path, compare_path, sensor):
1818 self .focal_length_compare = []
1919 self .crop = self .getCropSize (sensor )
2020
21- def getImages (self , whichpath ):
22- try :
23- return os .listdir (whichpath )
24- except FileNotFoundError :
25- print ('The given path "' + whichpath + '" does not exist!' )
21+ def getImages (self , whichpath , extension = ['jpg' , 'tif' , 'tiff' ]):
22+ image_list = []
23+ # no fuzz with suffixes: make them to lowercase
24+ extension_lower = []
25+ for x in extension :
26+ extension_lower .append (x .lower ())
27+
28+ for dirpath , dirnames , files in os .walk (whichpath ):
29+ for name in files :
30+ if extension and name .lower ().endswith (tuple (extension_lower )):
31+ image_list .append (os .path .join (dirpath , name ))
32+ #elif not extension:
33+ # print('No files with the given extensions' + extension + ' found!')
34+ return image_list
2635
2736 def extract (self ):
2837 # normal extraction
2938 for img in self .images :
3039 #print(self.images)
31- entry = self .getExifData ( Image .open (self . path + os . path . sep + img ) )
40+ entry = self .getExifData ( Image .open (img ) )
3241 if (entry ):
3342 self .focal_length .append (entry )
3443 print (self .focal_length )
3544 # extraction for comparing directory
3645 if (self .compareMode ):
3746 for img in self .compare_images :
3847 #print(self.compare_images)
39- entry = self .getExifData ( Image .open (self . compare_path + os . path . sep + img ) )
48+ entry = self .getExifData ( Image .open (img ) )
4049 if (entry ):
4150 self .focal_length_compare .append (entry )
4251 print (self .focal_length_compare )
@@ -61,11 +70,15 @@ def getCropSize(self, sensor):
6170
6271 def getExifData (self , img ):
6372 print (img .filename )
64- exif_data = {
65- ExifTags .TAGS [k ]: v
66- for k , v in img ._getexif ().items ()
67- if k in ExifTags .TAGS
68- }
73+ try :
74+ exif_data = {
75+ ExifTags .TAGS [k ]: v
76+ for k , v in img ._getexif ().items ()
77+ if k in ExifTags .TAGS
78+ }
79+ except AttributeError :
80+ print ('No exif data found for ' + img .filename + '.' )
81+ return None
6982 #print(exif_data)
7083 #print(focal_length)
7184 if (self .crop < 0 ): # local sensor without recalculation
0 commit comments