def read_ground_control_points(fileobj, reference): """Read ground control points from json file. Returns list of types.GroundControlPoint. """ obj = json_load(fileobj) points = [] for point_dict in obj['points']: point = types.GroundControlPoint() point.id = point_dict['id'] point.lla = point_dict.get('position') if point.lla: point.coordinates = reference.to_topocentric( point.lla['latitude'], point.lla['longitude'], point.lla.get('altitude', 0)) point.has_altitude = ('altitude' in point.lla) point.observations = [] for o_dict in point_dict['observations']: o = types.GroundControlPointObservation() o.shot_id = o_dict['shot_id'] if 'projection' in o_dict: o.projection = np.array(o_dict['projection']) point.observations.append(o) points.append(point) return points
def _read_gcp_list_lines(lines, projection, reference, exif): points = {} for line in lines: words = line.split(None, 5) easting, northing, alt, pixel_x, pixel_y = map(float, words[:5]) shot_id = words[5].strip() key = (easting, northing, alt) if key in points: point = points[key] else: # Convert 3D coordinates if np.isnan(alt): alt = 0 has_altitude = False else: has_altitude = True if projection is not None: lon, lat = projection(easting, northing, inverse=True) else: lon, lat = easting, northing point = types.GroundControlPoint() point.id = "unnamed-%d" % len(points) point.lla = np.array([lat, lon, alt]) point.has_altitude = has_altitude if reference: x, y, z = reference.to_topocentric(lat, lon, alt) point.coordinates = np.array([x, y, z]) else: point.coordinates = None points[key] = point # Convert 2D coordinates d = exif[shot_id] coordinates = features.normalized_image_coordinates( np.array([[pixel_x, pixel_y]]), d['width'], d['height'])[0] o = types.GroundControlPointObservation() o.shot_id = shot_id o.projection = coordinates point.observations.append(o) return list(points.values())
def read_ground_control_points(fileobj, reference): """Read ground control points from json file. Returns list of types.GroundControlPoint. """ obj = json_load(fileobj) points = [] for point_dict in obj['points']: point = types.GroundControlPoint() point.id = point_dict['id'] point.lla = point_dict.get('position') if point.lla: point.has_altitude = ('altitude' in point.lla) if reference: point.coordinates = reference.to_topocentric( point.lla['latitude'], point.lla['longitude'], point.lla.get('altitude', 0)) else: point.coordinates = None point.observations = [] observing_images = set() for o_dict in point_dict['observations']: o = types.GroundControlPointObservation() o.shot_id = o_dict['shot_id'] if o.shot_id in observing_images: logger.warning("GCP {} has multiple observations in image {}" .format(point.id, o.shot_id)) observing_images.add(o.shot_id) if 'projection' in o_dict: o.projection = np.array(o_dict['projection']) point.observations.append(o) points.append(point) return points