class TestLocalGeoCS(unittest.TestCase): @classmethod def setUp(self): self.wgs = geodesy.SRID.lat_lon_WGS84 self.geo1 = GeoPoint(np.array([-73.75898515, 42.85012609, 0]), self.wgs) self.geo2 = GeoPoint(np.array([-73.75623008, 42.89913984, 52.381]), self.wgs) def test_init(self): LocalGeoCS() def test_origin(self): g = LocalGeoCS() g.geo_origin = self.geo1 np.testing.assert_array_almost_equal(g.geo_origin.location(self.wgs), self.geo1.location()) def test_read_write_localgeocs(self): g = LocalGeoCS() g.geo_origin = self.geo1 f = open("geo_data.txt", "w+") f.close() local_geo_cs.write_local_geo_cs_to_file(g, "geo_data.txt") g2 = LocalGeoCS() local_geo_cs.read_local_geo_cs_from_file(g2, "geo_data.txt") np.testing.assert_array_almost_equal(g2.geo_origin.location(self.wgs), self.geo1.location())
def test_set_and_get_location(self): qr = self._create_query_result() crs_ll = g.SRID.lat_lon_WGS84 crs_utm_18n = g.SRID.UTM_WGS84_north + 18 nt.ok_(qr.location.is_empty()) p = GeoPoint(np.array([-73.759291, 42.849631]), crs_ll) qr.location = p nt.assert_equals(qr.location.crs(), crs_ll) np.testing.assert_array_almost_equal(qr.location.location(), p.location()) # Increase the precision, add altitude p = GeoPoint(np.array([77.397577193572642, 38.17996907564275, 50]), crs_ll) qr.location = p nt.assert_equals(qr.location.crs(), crs_ll) np.testing.assert_array_almost_equal(qr.location.location(), p.location(), decimal=15) # Try different crs p = GeoPoint(np.array([601375.01, 4744863.31]), crs_utm_18n) qr.location = p nt.assert_equals(qr.location.crs(), crs_utm_18n) np.testing.assert_array_almost_equal(qr.location.location(), p.location()) # Back to empty qr.location = GeoPoint() nt.ok_(qr.location.is_empty())
def setUp(self): self.meta_ = SimpleMetadataMap() self.geo_ = LocalGeoCS() self.small_tag = [ mt.tags.VITAL_META_UNKNOWN, mt.tags.VITAL_META_UNIX_TIMESTAMP, mt.tags.VITAL_META_SLANT_RANGE, mt.tags.VITAL_META_MISSION_ID, mt.tags.VITAL_META_VIDEO_KEY_FRAME, ] self.loc1 = np.array([-73.759291, 42.849631]) self.crs_ll = geodesy.SRID.lat_lon_WGS84 self.geo_pt1_ = GeoPoint(self.loc1, self.crs_ll) self.geo_.geo_origin = self.geo_pt1_
def test_conversion(self): modules.load_known_modules() geo_outA = GeoPoint() lc_lla = LocalCartesian(self.origA) lc_lla.convert_from_cartesian(self.offset1, geo_outA) self.compare_lla(geo_outA.location(), self.geo1.location()) cart_outA = lc_lla.convert_to_cartesian(geo_outA) self.compare_lla(cart_outA, self.offset1) lc_lla.convert_from_cartesian(self.offset2, geo_outA) self.compare_lla(geo_outA.location(), self.geo2.location()) cart_outA = lc_lla.convert_to_cartesian(geo_outA) self.compare_lla(cart_outA, self.offset2) geo_outB = GeoPoint() lc_utm = LocalCartesian(self.origB) lc_utm.convert_from_cartesian(self.offset1, geo_outB) self.compare_lla(geo_outB.location(), self.geo1.location()) cart_outB = lc_utm.convert_to_cartesian(geo_outB) self.compare_lla(cart_outB, self.offset1) lc_utm.convert_from_cartesian(self.offset2, geo_outB) self.compare_lla(geo_outB.location(), self.geo2.location()) cart_outB = lc_utm.convert_to_cartesian(geo_outB) self.compare_lla(cart_outB, self.offset2)
def test_get_set_geo_point(self): do = DetectedObject(self.bbox) # Check default nt.ok_(self.check_geo_points_equal(do.geo_point, GeoPoint())) # Setting to different value do.geo_point = self.geo_point nt.ok_(self.check_geo_points_equal(do.geo_point, self.geo_point))
def setUp(self): self.g_point = GeoPoint(np.array([1, 2, 3]), gd.SRID.lat_lon_WGS84) poly = Polygon([ np.array([10, 10]), np.array([10, 50]), np.array([50, 50]), np.array([30, 30]), ]) self.g_poly = GeoPolygon(poly, gd.SRID.lat_lon_WGS84)
def setUp(self): self.wgs = geodesy.SRID.lat_lon_WGS84 self.crs_utm_18n = geodesy.SRID.UTM_WGS84_north + 18 self.origA = GeoPoint(np.array([-73.759291, 42.849631, 0]), self.wgs) self.origB = GeoPoint(np.array([601375.01, 4744863.31, 0]), self.crs_utm_18n) self.offset1 = np.array([25, 55, 0]) self.offset2 = np.array([250, 5500, 50]) self.geo1 = GeoPoint(np.array([-73.75898515, 42.85012609, 0]), self.wgs) self.geo2 = GeoPoint(np.array([-73.75623008, 42.89913984, 52.381]), self.wgs)
def setUp(self): self.loc1 = np.array([-73.759291, 42.849631]) self.loc2 = np.array([-149.484444, -17.619482]) self.bbox = BoundingBox(10, 10, 20, 20) self.conf = 0.5 self.dot = DetectedObjectType("example_class", 0.4) self.mask = ImageContainer(Image(1080, 720)) # Values to set outside of constructor self.geo_point = GeoPoint(self.loc1, geodesy.SRID.lat_lon_WGS84) self.index = 5 self.detector_name = "example_detector_name" self.descriptor = descriptor.new_descriptor(5) self.descriptor[:] = 10 self.note_to_add = "example_note" self.keypoint_to_add = Point2d() self.keypoint_to_add.value = self.loc2 self.keypoint_id = "example_keypoint_id"
def setUp(self): self.wgs = geodesy.SRID.lat_lon_WGS84 self.geo1 = GeoPoint(np.array([-73.75898515, 42.85012609, 0]), self.wgs) self.geo2 = GeoPoint(np.array([-73.75623008, 42.89913984, 52.381]), self.wgs)
class TestSFMConstraints(unittest.TestCase): @classmethod def setUp(self): self.meta_ = SimpleMetadataMap() self.geo_ = LocalGeoCS() self.small_tag = [ mt.tags.VITAL_META_UNKNOWN, mt.tags.VITAL_META_UNIX_TIMESTAMP, mt.tags.VITAL_META_SLANT_RANGE, mt.tags.VITAL_META_MISSION_ID, mt.tags.VITAL_META_VIDEO_KEY_FRAME, ] self.loc1 = np.array([-73.759291, 42.849631]) self.crs_ll = geodesy.SRID.lat_lon_WGS84 self.geo_pt1_ = GeoPoint(self.loc1, self.crs_ll) self.geo_.geo_origin = self.geo_pt1_ def test_init(self): s = SFMConstraints() SFMConstraints(s) SFMConstraints(self.meta_, self.geo_) def test_properties(self): # modules.load_known_modules() # metadata property s = SFMConstraints(self.meta_, self.geo_) get_meta = s.metadata nt.assert_equal(get_meta.size(), 0) m = SimpleMetadataMap() s.metadata = m nt.assert_equal(s.metadata.size(), 0) # local_geo_property ret_geo = s.local_geo_cs np.testing.assert_array_almost_equal(ret_geo.geo_origin.location(self.crs_ll), self.geo_pt1_.location()) s = SFMConstraints() s.local_geo_cs = self.geo_ ret_geo = s.local_geo_cs np.testing.assert_array_almost_equal(ret_geo.geo_origin.location(self.crs_ll), self.geo_pt1_.location()) def test_get_camera_position_prior_local(self): s = SFMConstraints(self.meta_, self.geo_) nt.assert_false(s.get_camera_position_prior_local(0, np.array([0, 1, 3]))) nt.assert_false(s.get_camera_position_prior_local(0, RotationD([1, 2, 3, 4]))) def test_camera_position_priors(self): s = SFMConstraints(self.meta_, self.geo_) nt.assert_dict_equal(s.get_camera_position_priors(), {}) def test_image_properties(self): s = SFMConstraints(self.meta_, self.geo_) s.store_image_size(0, 1080, 720) a,b = 0,0 founda, foundb = False, False founda, a = s.get_image_width(0, a) foundb, b = s.get_image_height(0, b) nt.ok_(founda) nt.ok_(foundb) nt.assert_equal(a, 1080) nt.assert_equal(b, 720) found_focal = True focal_len = 0.1 found_focal, focal_len = s.get_focal_length_prior(0, focal_len) nt.assert_false(found_focal) nt.assert_almost_equal(focal_len, 0.1)
class TestVitalLocalCartesian(unittest.TestCase): def setUp(self): self.wgs = geodesy.SRID.lat_lon_WGS84 self.crs_utm_18n = geodesy.SRID.UTM_WGS84_north + 18 self.origA = GeoPoint(np.array([-73.759291, 42.849631, 0]), self.wgs) self.origB = GeoPoint(np.array([601375.01, 4744863.31, 0]), self.crs_utm_18n) self.offset1 = np.array([25, 55, 0]) self.offset2 = np.array([250, 5500, 50]) self.geo1 = GeoPoint(np.array([-73.75898515, 42.85012609, 0]), self.wgs) self.geo2 = GeoPoint(np.array([-73.75623008, 42.89913984, 52.381]), self.wgs) def test_create(self): LocalCartesian(self.origA, 0) LocalCartesian(self.origA, 33) def test_initial_origin(self): lc = LocalCartesian(self.origA, 0) np.testing.assert_array_almost_equal(lc.get_origin().location(), self.origA.location()) lc = LocalCartesian(self.origA, 33) np.testing.assert_array_almost_equal(lc.get_origin().location(), self.origA.location()) def test_initial_orientation(self): lc = LocalCartesian(self.origA, 0) nt.assert_equal(lc.get_orientation(), 0) lc = LocalCartesian(self.origA, 33) nt.assert_equal(lc.get_orientation(), 33) def check_origin_and_orient_equal(self, lc, origin, orient): np.testing.assert_array_almost_equal(lc.get_origin().location(), origin.location()) nt.assert_equal(lc.get_orientation(), orient) def test_api(self): lc = LocalCartesian(self.origA, 0) lc.set_origin(self.geo1, 33) self.check_origin_and_orient_equal(lc, self.geo1, 33) lc.set_origin(self.geo2, 22) self.check_origin_and_orient_equal(lc, self.geo2, 22) def test_default_args(self): # Default value of orientation arg = 0 lc = LocalCartesian(self.origA) self.check_origin_and_orient_equal(lc, self.origA, 0) # Test calling set_origin with named parameters lc.set_origin(orientation=33, origin=self.geo1) self.check_origin_and_orient_equal(lc, self.geo1, 33) # Now test named parameters of constructors lc = LocalCartesian(orientation=33, origin=self.origA) self.check_origin_and_orient_equal(lc, self.origA, 33) # Then default value of orientation argument for set_origin lc.set_origin(self.geo1) self.check_origin_and_orient_equal(lc, self.geo1, 0) def compare_lla(self, gp1, gp2): np.testing.assert_almost_equal(gp1[0], gp2[0], 7) np.testing.assert_almost_equal(gp1[1], gp2[1], 7) np.testing.assert_almost_equal(gp1[2], gp2[2], 3) def test_conversion(self): modules.load_known_modules() geo_outA = GeoPoint() lc_lla = LocalCartesian(self.origA) lc_lla.convert_from_cartesian(self.offset1, geo_outA) self.compare_lla(geo_outA.location(), self.geo1.location()) cart_outA = lc_lla.convert_to_cartesian(geo_outA) self.compare_lla(cart_outA, self.offset1) lc_lla.convert_from_cartesian(self.offset2, geo_outA) self.compare_lla(geo_outA.location(), self.geo2.location()) cart_outA = lc_lla.convert_to_cartesian(geo_outA) self.compare_lla(cart_outA, self.offset2) geo_outB = GeoPoint() lc_utm = LocalCartesian(self.origB) lc_utm.convert_from_cartesian(self.offset1, geo_outB) self.compare_lla(geo_outB.location(), self.geo1.location()) cart_outB = lc_utm.convert_to_cartesian(geo_outB) self.compare_lla(cart_outB, self.offset1) lc_utm.convert_from_cartesian(self.offset2, geo_outB) self.compare_lla(geo_outB.location(), self.geo2.location()) cart_outB = lc_utm.convert_to_cartesian(geo_outB) self.compare_lla(cart_outB, self.offset2)
def test_driver(self): # GPS_WEEK - int tag = mt.tags.VITAL_META_GPS_WEEK inst1 = TypedMetadata_GPS_WEEK("GPS_WEEK_NAME1", 3) inst2 = TypedMetadata_GPS_WEEK("GPS_WEEK_NAME2", -3) type_info1 = TypeInfo("int", as_string="3") type_info2 = TypeInfo("int", as_string="-3") self.check_instance(inst1, PropInfo("GPS_WEEK_NAME1", tag, 3), type_info1) self.check_instance(inst2, PropInfo("GPS_WEEK_NAME2", tag, -3), type_info2) # UNIX_TIMESTAMP - uint64 tag = mt.tags.VITAL_META_UNIX_TIMESTAMP inst1 = TypedMetadata_UNIX_TIMESTAMP("UNIX_TIMESTAMP_NAME1", 5) inst2 = TypedMetadata_UNIX_TIMESTAMP("UNIX_TIMESTAMP_NAME2", 0) prop_info1 = PropInfo("UNIX_TIMESTAMP_NAME1", tag, 5) prop_info2 = PropInfo("UNIX_TIMESTAMP_NAME2", tag, 0) type_impl = tc.get_uint64_rep() type_info1 = TypeInfo(type_impl, has_uint64=True, as_uint64=5, as_string="5") type_info2 = TypeInfo(type_impl, has_uint64=True, as_uint64=0, as_string="0") self.check_instance(inst1, prop_info1, type_info1) self.check_instance(inst2, prop_info2, type_info2) # SLANT_RANGE - double tag = mt.tags.VITAL_META_SLANT_RANGE inst1 = TypedMetadata_SLANT_RANGE("SLANT_RANGE_NAME1", 3.14) inst2 = TypedMetadata_SLANT_RANGE("SLANT_RANGE_NAME2", -3.14) prop_info1 = PropInfo("SLANT_RANGE_NAME1", tag, 3.14) prop_info2 = PropInfo("SLANT_RANGE_NAME2", tag, -3.14) type_info1 = TypeInfo("double", has_double=True, as_double=3.14, as_string="3.14") type_info2 = TypeInfo("double", has_double=True, as_double=-3.14, as_string="-3.14") self.check_instance(inst1, prop_info1, type_info1) self.check_instance(inst2, prop_info2, type_info2) # MISSION_ID - string tag = mt.tags.VITAL_META_MISSION_ID inst1 = TypedMetadata_MISSION_ID("MISSION_ID_NAME1", "") inst2 = TypedMetadata_MISSION_ID("MISSION_ID_NAME2", "data123") prop_info1 = PropInfo("MISSION_ID_NAME1", tag, "") prop_info2 = PropInfo("MISSION_ID_NAME2", tag, "data123") type_info1 = TypeInfo("string", has_string=True, as_string="") type_info2 = TypeInfo("string", has_string=True, as_string="data123") self.check_instance(inst1, prop_info1, type_info1) self.check_instance(inst2, prop_info2, type_info2) # VIDEO_KEY_FRAME - bool tag = mt.tags.VITAL_META_VIDEO_KEY_FRAME inst1 = TypedMetadata_VIDEO_KEY_FRAME("VIDEO_KEY_FRAME_NAME1", True) inst2 = TypedMetadata_VIDEO_KEY_FRAME("VIDEO_KEY_FRAME_NAME2", False) type_info1 = TypeInfo("bool", as_string="True") type_info2 = TypeInfo("bool", as_string="False") self.check_instance(inst1, PropInfo("VIDEO_KEY_FRAME_NAME1", tag, True), type_info1) self.check_instance(inst2, PropInfo("VIDEO_KEY_FRAME_NAME2", tag, False), type_info2) # FRAME_CENTER - kwiver::vital::geo_point tag = mt.tags.VITAL_META_FRAME_CENTER inst1 = TypedMetadata_FRAME_CENTER("FRAME_CENTER_NAME1", GeoPoint()) inst2 = TypedMetadata_FRAME_CENTER("FRAME_CENTER_NAME2", self.g_point) type_info1 = TypeInfo("kwiver::vital::geo_point", as_string=str(GeoPoint())) type_info2 = TypeInfo("kwiver::vital::geo_point", as_string=str(self.g_point)) self.check_instance(inst1, PropInfo("FRAME_CENTER_NAME1", tag, GeoPoint()), type_info1) self.check_instance(inst2, PropInfo("FRAME_CENTER_NAME2", tag, self.g_point), type_info2) # CORNER_POINTS - kwiver::vital::geo_polygon tag = mt.tags.VITAL_META_CORNER_POINTS inst1 = TypedMetadata_CORNER_POINTS("CORNER_POINTS_NAME1", GeoPolygon()) inst2 = TypedMetadata_CORNER_POINTS("CORNER_POINTS_NAME2", self.g_poly) type_info1 = TypeInfo("kwiver::vital::geo_polygon", as_string=str(GeoPolygon())) type_info2 = TypeInfo("kwiver::vital::geo_polygon", as_string=str(self.g_poly)) self.check_instance(inst1, PropInfo("CORNER_POINTS_NAME1", tag, GeoPolygon()), type_info1) self.check_instance(inst2, PropInfo("CORNER_POINTS_NAME2", tag, self.g_poly), type_info2) # UNKNOWN - int. There's also a separate class for the unknown tag, # which will be tested later tag = mt.tags.VITAL_META_UNKNOWN inst1 = TypedMetadata_UNKNOWN("UNKNOWN_NAME1", 2) inst2 = TypedMetadata_UNKNOWN("UNKNOWN_NAME2", -2) type_info1 = TypeInfo("int", as_string="2") type_info2 = TypeInfo("int", as_string="-2") self.check_instance(inst1, PropInfo("UNKNOWN_NAME1", tag, 2), type_info1) self.check_instance(inst2, PropInfo("UNKNOWN_NAME2", tag, -2), type_info2) # UnknownMetadataItem - This is a separate subclass of metadata_item # Can keep the tag the same inst = UnknownMetadataItem() exp_name = "Requested metadata item is not in collection" exp_string = "--Unknown metadata item--" prop_info = PropInfo(exp_name, tag, 0) type_info = TypeInfo("void", as_string=exp_string, as_double=0, as_uint64=0) self.check_instance(inst, prop_info, type_info, is_valid=False)
def test_driver(self): # GPS_WEEK - int tag = mt.tags.VITAL_META_GPS_WEEK inst1 = MetadataItem(tag, 3) inst2 = MetadataItem(tag, -3) type_info1 = TypeInfo("int", as_string="3") type_info2 = TypeInfo("int", as_string="-3") self.check_instance(inst1, PropInfo("GPS Week", tag, 3), type_info1) self.check_instance(inst2, PropInfo("GPS Week", tag, -3), type_info2) # UNIX_TIMESTAMP - uint64 tag = mt.tags.VITAL_META_UNIX_TIMESTAMP inst1 = MetadataItem(tag, 5) inst2 = MetadataItem(tag, 0) prop_info1 = PropInfo("Unix Timestamp (microseconds)", tag, 5) prop_info2 = PropInfo("Unix Timestamp (microseconds)", tag, 0) type_impl = tc.get_uint64_rep() type_info1 = TypeInfo(type_impl, has_uint64=True, as_uint64=5, as_string="5") type_info2 = TypeInfo(type_impl, has_uint64=True, as_uint64=0, as_string="0") self.check_instance(inst1, prop_info1, type_info1) self.check_instance(inst2, prop_info2, type_info2) # SLANT_RANGE - double tag = mt.tags.VITAL_META_SLANT_RANGE inst1 = MetadataItem(tag, 3.14) inst2 = MetadataItem(tag, -3.14) prop_info1 = PropInfo("Slant Range (meters)", tag, 3.14) prop_info2 = PropInfo("Slant Range (meters)", tag, -3.14) type_info1 = TypeInfo("double", has_double=True, as_double=3.14, as_string="3.14") type_info2 = TypeInfo("double", has_double=True, as_double=-3.14, as_string="-3.14") self.check_instance(inst1, prop_info1, type_info1) self.check_instance(inst2, prop_info2, type_info2) # MISSION_ID - string tag = mt.tags.VITAL_META_MISSION_ID inst1 = MetadataItem(tag, "") inst2 = MetadataItem(tag, "data123") prop_info1 = PropInfo("Mission ID", tag, "") prop_info2 = PropInfo("Mission ID", tag, "data123") type_info1 = TypeInfo("string", has_string=True, as_string="") type_info2 = TypeInfo("string", has_string=True, as_string="data123") self.check_instance(inst1, prop_info1, type_info1) self.check_instance(inst2, prop_info2, type_info2) # VIDEO_KEY_FRAME - bool tag = mt.tags.VITAL_META_VIDEO_KEY_FRAME inst1 = MetadataItem(tag, True) inst2 = MetadataItem(tag, False) type_info1 = TypeInfo("bool", as_string="True") type_info2 = TypeInfo("bool", as_string="False") self.check_instance(inst1, PropInfo("Is Key Frame", tag, True), type_info1) self.check_instance(inst2, PropInfo("Is Key Frame", tag, False), type_info2) # FRAME_CENTER - kwiver::vital::geo_point tag = mt.tags.VITAL_META_FRAME_CENTER inst1 = MetadataItem(tag, GeoPoint()) inst2 = MetadataItem(tag, self.g_point) type_info1 = TypeInfo("kwiver::vital::geo_point", as_string=str(GeoPoint())) type_info2 = TypeInfo("kwiver::vital::geo_point", as_string=str(self.g_point)) self.check_instance( inst1, PropInfo("Geodetic Frame Center (lon/lat/alt)", tag, GeoPoint()), type_info1) self.check_instance( inst2, PropInfo("Geodetic Frame Center (lon/lat/alt)", tag, self.g_point), type_info2) # CORNER_POINTS - kwiver::vital::geo_polygon tag = mt.tags.VITAL_META_CORNER_POINTS inst1 = MetadataItem(tag, GeoPolygon()) inst2 = MetadataItem(tag, self.g_poly) type_info1 = TypeInfo("kwiver::vital::geo_polygon", as_string=str(GeoPolygon())) type_info2 = TypeInfo("kwiver::vital::geo_polygon", as_string=str(self.g_poly)) self.check_instance( inst1, PropInfo("Corner Points (lon/lat)", tag, GeoPolygon()), type_info1) self.check_instance( inst2, PropInfo("Corner Points (lon/lat)", tag, self.g_poly), type_info2) # UNKNOWN - int tag = mt.tags.VITAL_META_UNKNOWN inst1 = MetadataItem(tag, 2) inst2 = MetadataItem(tag, -2) type_info1 = TypeInfo("int", as_string="2") type_info2 = TypeInfo("int", as_string="-2") self.check_instance(inst1, PropInfo("Unknown / Undefined Entry", tag, 2), type_info1, False) self.check_instance(inst2, PropInfo("Unknown / Undefined Entry", tag, -2), type_info2, False)