From 2de116915b3841f4605a2cc779c931e2c7728d18 Mon Sep 17 00:00:00 2001 From: edgarriba Date: Fri, 27 Nov 2015 10:00:08 +0000 Subject: [PATCH] refactor ODMPhoto --- opendm/types.py | 148 ++++++++++-------------------------------------- 1 file changed, 31 insertions(+), 117 deletions(-) diff --git a/opendm/types.py b/opendm/types.py index 65af99f3..337c655f 100644 --- a/opendm/types.py +++ b/opendm/types.py @@ -20,52 +20,40 @@ class ODMPhoto: self.focal_length = None self.focal_length_px = None # other attributes - self.file_size = None - self.file_date = None self.camera_make = None self.camera_model = None - self.date_time = None - self.resolution = None - self.flash_used = None - self.exposure_time = None - self.aperture = None - self.focus_distance = None - self.iso_equiv = None - self.white_balance = None - self.light_source = None - self.metering_mode = None - self.exposure = None - self.exposure_mode = None - self.exposure_bias = None - self.orientation = None - self.gps_latitude = None - self.gps_longitude = None - self.gps_altitude = None - self.jpg_quality = None - - # parse values - #self.parse_jhead_values(self.path_file, args) + # parse values from metadata self.parse_pyexiv2_values(self.path_file, args) - # compute focal lenght into pixels self.compute_focal_length() def compute_focal_length(self): - if self.focal_length is not None and self.ccd_width is not None: - # compute the focal lenth in pixels + # set log message + msg = 'Loaded %s | dimensions: %s x %s' % \ + (self.filename, self.width, self.height) + + # compute focal length in pixels + if self.focal_length and self.ccd_width: + # take width or height as reference if self.width > self.height: + # f(px) = w(px) * f(mm) / ccd(mm) self.focal_length_px = \ self.width * (self.focal_length / self.ccd_width) else: + # f(px) = h(px) * f(mm) / ccd(mm) self.focal_length_px = \ self.height * (self.focal_length / self.ccd_width) - - log.ODM_DEBUG('Loaded %s | dimensions: %s x %s | focal: %smm | ccd: %smm' % \ - (self.filename, self.width, self.height, self.focal_length, self.ccd_width)) + # update log message + msg += ' | focal: %smm | ccd: %smm' % (self.focal_length, self.ccd_width) else: - log.ODM_WARNING('No CCD width or focal length found for image file: \n' + - self.filename + ' camera: \"' + self.camera_model) - + # update log message + if self.focal_length: + msg += ' | focal: %smm' % self.focal_length + + if self.ccd_width: + msg += ' | ccd: %smm' % self.ccd_width + # print log message + log.ODM_DEBUG(msg) def parse_pyexiv2_values(self, _path_file, args): # read image metadata @@ -80,8 +68,7 @@ class ODMPhoto: elif key == 'Exif.Image.Model': self.camera_model = val elif key == 'Exif.Photo.PixelXDimension': self.width = val elif key == 'Exif.Photo.PixelYDimension': self.height = val - elif key == 'Exif.Photo.FocalLength': - self.focal_length = float(val) + elif key == 'Exif.Photo.FocalLength': self.focal_length = float(val) # extract and set filename from path file self.filename = io.extract_file_from_path_file(_path_file) @@ -93,88 +80,15 @@ class ODMPhoto: # search ccd by camera model key = [x for x in ccd_widths.keys() if self.camera_model in x] # convert to float if found - if len(key) > 0: - self.ccd_width = float(ccd_widths[key][0]) - else: - log.ODM_ERROR('Could not find ccd_width in file') + if key: self.ccd_width = float(ccd_widths[key][0]) + # else: + # log.ODM_ERROR('Could not find ccd_width in file') - def parse_jhead_values(self, _path_file, args): - - # load ccd_widths from file - ccd_widths = system.get_ccd_widths() - - # start pipe for jhead - src_process = subprocess.Popen(['jhead', _path_file], - stdout=subprocess.PIPE) - std_out, std_err = src_process.communicate() - - # split lines since the output has not a standard format - std_out = std_out.decode('ascii') - std_out = std_out.splitlines() - - # loop overl lines - for line in std_out[:-1]: - # split line in two parts and catch keys and values - key, val = [x.strip() for x in line.split(':')][:2] - - # parse values to attributes - if key == 'File name': - self.path_file = val - self.filename = io.extract_file_from_path_file(val) - elif key == 'File size': self.file_size = val - elif key == 'File date': self.file_date = val - elif key == 'Camera make': self.camera_make = val - elif key == 'Camera model': self.camera_model = val - elif key == 'Date/Time': self.date_time = val - - # parse resolution field - elif key == 'Resolution': - width, height = val.split(' x ')[:2] - self.width = int(width) - self.height = int(height) - - # parse resolution field - elif key == 'Flash used': - self.flash_used = bool(val) - - # parse force-focal - elif key == 'Focal length': - if args.get('force_focal') is not None: - self.focal_length = args['force_focal'] - else: - self.focal_length = float(val.split(' ')[0][:-2]) - - # parse force-ccd - elif key == 'CCD width': - if args.get('force_ccd') is not None: - self.ccd_width = args['force_ccd'] - else: - self.ccd_width = float(val[:-2]) - - elif key == 'Exposure time': self.exposure_time = val - elif key == 'Aperture': self.aperture = val - elif key == 'Focus dist.': self.focus_dist = val - elif key == 'ISO equiv.': self.iso_equiv = val - elif key == 'Whitebalance': self.white_balance = val - elif key == 'Light Source': self.light_source = val - elif key == 'Metering Mode': self.metering_mode = val - elif key == 'Exposure': self.exposure = val - elif key == 'Exposure Mode': self.exposure_mode = val - elif key == 'Exposure bias': self.exposure_bias = val - elif key == 'Orientation': self.orientation = val - elif key == 'GPS Latitude': self.gps_latitude = val - elif key == 'GPS Longitude': self.gps_longitude = val - elif key == 'GPS Altitude': self.gps_altitude = val - elif key == 'JPEG Quality': self.jpg_quality = val - else: - log.ODM_WARNING('Unknown key: %s' % key) - - # find ccd_width from file if needed - if self.ccd_width is None: - key = [x for x in ccd_widths.keys() if self.camera_model in x][0] - if key is not None: - self.ccd_width = float(ccd_widths[key]) - else: - log.ODM_ERROR('Could not find ccd_width in file') - \ No newline at end of file +# TODO: finish this class +class ODMReconstruction(object): + """docstring for ODMReconstruction""" + def __init__(self, arg): + super(ODMReconstruction, self).__init__() + self.arg = arg + \ No newline at end of file