示例#1
0
def test_register():
    from kwiver.vital.config import config
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.sprokit.pipeline import scheduler_factory

    modules.load_known_modules()

    sched_type = 'python_example'
    sched_desc = 'simple description'

    scheduler_factory.add_scheduler(sched_type, sched_desc,
                                    example_scheduler(True))

    if not sched_desc == scheduler_factory.description(sched_type):
        test_error("Description was not preserved when registering")

    p = pipeline.Pipeline()

    try:
        s = scheduler_factory.create_scheduler(sched_type, p)
        if s is None:
            raise Exception()
    except:
        test_error("Could not create newly registered scheduler type")
示例#2
0
def test_api_calls():
    from kwiver.vital.config import config
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import process
    from kwiver.sprokit.pipeline import process_factory

    modules.load_known_modules()

    proc_type = 'orphan'
    c = config.empty_config()

    process_factory.create_process(proc_type, '')
    process_factory.create_process(proc_type, '', c)
    process_factory.types()
    process_factory.description(proc_type)

    process_factory.Process.property_no_threads
    process_factory.Process.property_no_reentrancy
    process_factory.Process.property_unsync_input
    process_factory.Process.property_unsync_output
    process_factory.Process.port_heartbeat
    process_factory.Process.config_name
    process_factory.Process.config_type
    process_factory.Process.type_any
    process_factory.Process.type_none
    process_factory.Process.type_data_dependent
    process_factory.Process.type_flow_dependent
    process_factory.Process.flag_output_const
    process_factory.Process.flag_input_static
    process_factory.Process.flag_input_mutable
    process_factory.Process.flag_input_nodep
    process_factory.Process.flag_required
示例#3
0
    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)
示例#4
0
def create_process(type, name, conf):
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import process_factory

    modules.load_known_modules()

    p = process_factory.create_process(type, name, conf)

    return p
示例#5
0
 def test_detect(self):
     modules.load_known_modules()
     detector = ImageObjectDetector.create("example_detector")
     image = Image()
     image_container = ImageContainer(image)
     detections = detector.detect(image_container)
     nose.tools.ok_(detections is not None,
                    "Unexpected empty detections" )
     nose.tools.assert_equal(len(detections), 1)
示例#6
0
 def setUp(self):
     modules.load_known_modules()
     self.instance = Transform2DIO.create("SimpleTransform2DIO")
     #TODO: Replace these mocks with the actual vital types
     # The successful tests in this file are not indicators of anything being
     # tested they are failing because the function signature does not match
     # with what pybind11 expects. We would modify these tests once the
     # vital types bindings are complete so that we can test for the desired
     # behavior
     self.transform_2d = Mock()
示例#7
0
def test_masking():
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import process_factory

    modules.load_known_modules()

    types = process_factory.types()

    if 'test_python_process' in types:
        test_error("Failed to mask out Python processes")
示例#8
0
def test_extra_modules():
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import process_factory

    modules.load_known_modules()

    types = process_factory.types()

    if 'extra_test_python_process' not in types:
        test_error("Failed to load extra Python processes")
示例#9
0
 def test_config(self):
     modules.load_known_modules()
     detector = ImageObjectDetector.create("example_detector")
     # Verify that 6 config values are present in example_detector
     nose.tools.assert_equal(len(detector.get_configuration()), 6)
     test_cfg = _dummy_detector_cfg()
     # Verify that the detector has different configuration before setting to test
     nose.tools.assert_not_equal(detector.check_configuration(test_cfg), False)
     detector.set_configuration(test_cfg)
     # Verify that the config value is being set properly
     nose.tools.assert_equal(detector.check_configuration(test_cfg), True)
示例#10
0
 def get_algo_list(self):
     modules.load_known_modules()
     algo_list = []
     for v in kwiver.vital.algo.__dict__.values():
         if isinstance(v, type) and issubclass(
                 v, kwiver.vital.algo.algos._algorithm):
             simple_impl_name = "Simple" + v.__name__
             all_impl_names = [sc.__name__ for sc in v.__subclasses__()]
             # Note that we assume the structure of the name of the wrapper module
             if simple_impl_name in all_impl_names:
                 algo_list.append((v, simple_impl_name))
     return algo_list
 def test_read_set(self):
     """Create and configure a DetectedObjectSetInput and call .read_set"""
     load_known_modules()
     dosi = DetectedObjectSetInput.create('simulator')
     dosi.set_configuration(_create_simulator_config())
     sets = list(iter(dosi.read_set, None))
     self.assertEqual(len(sets), SIMULATOR_CONFIG['max_sets'])
     for s in sets:
         self.assertEqual(len(s), 2)
         dos, image_name = s
         self.assertIsInstance(dos, DetectedObjectSet)
         self.assertEqual(len(dos), SIMULATOR_CONFIG['set_size'])
         self.assertEqual(image_name, SIMULATOR_CONFIG['image_name'])
示例#12
0
    def test_conversion(self):
        modules.load_known_modules()

        gc_ll = GeoCovariance(self.loc1, self.crs_ll)
        gc_utm = GeoCovariance(self.loc3, self.crs_utm_18n)

        conv_loc_utm = gc_ll.location(gc_utm.crs())
        conv_loc_ll = gc_utm.location(gc_ll.crs())

        loc3_expected = np.concatenate([self.loc3, [0]])
        epsilon_ll_to_utm = np.linalg.norm(loc3_expected - conv_loc_utm)

        loc1_expected = np.concatenate([self.loc1, [0]])
        epsilon_utm_to_ll = np.linalg.norm(loc1_expected - conv_loc_ll)

        np.testing.assert_array_almost_equal(gc_ll.location(),
                                             conv_loc_ll,
                                             decimal=7)
        np.testing.assert_array_almost_equal(gc_utm.location(),
                                             conv_loc_utm,
                                             decimal=2)
        nt.ok_(epsilon_ll_to_utm < 10**(-2))
        nt.ok_(epsilon_utm_to_ll < 10**(-7))

        print("LL->UTM epsilon:", epsilon_ll_to_utm)
        print("UTM->LL epsilon:", epsilon_utm_to_ll)

        # Tests with altitude
        gc_lla = GeoCovariance(self.loc1a, self.crs_ll)
        gc_utma = GeoCovariance(self.loc3a, self.crs_utm_18n)

        conv_loc_utma = gc_lla.location(gc_utma.crs())
        conv_loc_lla = gc_utma.location(gc_lla.crs())

        epsilon_lla_to_utma = np.linalg.norm(self.loc3a - conv_loc_utma)
        epsilon_utma_to_lla = np.linalg.norm(self.loc1a - conv_loc_lla)

        np.testing.assert_array_almost_equal(gc_lla.location(),
                                             conv_loc_lla,
                                             decimal=7)
        np.testing.assert_array_almost_equal(gc_utma.location(),
                                             conv_loc_utma,
                                             decimal=2)
        nt.ok_(epsilon_lla_to_utma < 10**(-2))
        nt.ok_(epsilon_utma_to_lla < 10**(-7))

        print("LLa->UTMa epsilon:", epsilon_lla_to_utma)
        print("UTMa->LLa epsilon:", epsilon_utma_to_lla)
示例#13
0
def test_simple_pipeline(path):
    from kwiver.vital import config
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline_util import bake
    from kwiver.sprokit.pipeline_util import load

    blocks = load.load_pipe_file(path)

    modules.load_known_modules()

    bake.bake_pipe_file(path)
    with open(path, 'r') as fin:
        bake.bake_pipe(fin)
    bake.bake_pipe_blocks(blocks)
    bake.extract_configuration(blocks)
示例#14
0
def test_api_calls():
    from kwiver.vital.config import config
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.sprokit.pipeline import scheduler_factory

    modules.load_known_modules()

    sched_type = 'thread_per_process'
    c = config.empty_config()
    p = pipeline.Pipeline()

    scheduler_factory.create_scheduler(sched_type, p)
    scheduler_factory.create_scheduler(sched_type, p, c)
    scheduler_factory.types()
    scheduler_factory.description(sched_type)
    scheduler_factory.default_type
示例#15
0
def run_pipeline(sched_type, pipe, conf):
    from kwiver.vital.config import config
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import scheduler_factory
    import sys

    modules.load_known_modules()

    if sched_type in cpp_scheds:
        expect_exception("trying to run a python process on a C++ scheduler", RuntimeError,
                         scheduler_factory.create_scheduler, sched_type, pipe, conf)

    else:
        s = scheduler_factory.create_scheduler(sched_type, pipe, conf)

        s.start()
        s.wait()
示例#16
0
def test_wrapper_api():
    from kwiver.vital.config import config
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.sprokit.pipeline import process_factory
    from kwiver.sprokit.pipeline import scheduler_factory

    sched_type = 'python_example'
    sched_desc = 'simple description'

    modules.load_known_modules()

    scheduler_factory.add_scheduler(sched_type, sched_desc,
                                    example_scheduler(False))

    p = pipeline.Pipeline()

    proc_type = 'orphan'
    proc_name = 'orphan'

    proc = process_factory.create_process(proc_type, proc_name)

    p.add_process(proc)

    def check_scheduler(s):
        if s is None:
            test_error("Got a 'None' scheduler")
            return

        s.start()
        s.pause()
        s.resume()
        s.stop()
        s.start()
        s.wait()

        del s

    p.reset()
    p.setup_pipeline()

    s = scheduler_factory.create_scheduler(sched_type, p)
    check_scheduler(s)
示例#17
0
    def test_nested_config(self):
        modules.load_known_modules()
        detector = ImageObjectDetector.create("example_detector")
        nested_cfg = config.empty_config()
        ImageObjectDetector.get_nested_algo_configuration( "detector",
                                                            nested_cfg,
                                                            detector )
        # Verify that test cfg is set to configuration inside detector
        # nested configuration uses the name of a detector as an additional configuration
        # key thus it is checked against 7 rather than 6
        #nose.tools.assert_equal(len(nested_cfg), 7)

        #test_cfg = _dummy_detector_cfg()
        #test_cfg.set_value("example_detector:type", "example_detector")
        #ImageObjectDetector.set_nested_algo_configuration( "example_detector",
        #                                    test_cfg,
        #                                    detector )
        nose.tools.assert_equal(ImageObjectDetector.check_nested_algo_configuration(
                                                            "detector",
                                                            nested_cfg), True)
示例#18
0
def test_api_calls():
    from kwiver.vital.config import config
    from kwiver.sprokit.pipeline import datum
    from kwiver.sprokit.pipeline import edge
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import process
    from kwiver.sprokit.pipeline import process_factory
    from kwiver.sprokit.pipeline import stamp

    e = edge.Edge()

    e.makes_dependency()
    e.has_data()
    e.full_of_data()
    e.datum_count()

    d = datum.complete()
    s = stamp.new_stamp(1)

    ed = edge.EdgeDatum(d, s)

    e.push_datum(ed)
    e.get_datum()

    e.push_datum(ed)
    e.peek_datum()
    e.pop_datum()

    modules.load_known_modules()

    p = process_factory.create_process('orphan', 'process_name')

    e.set_upstream_process(p)
    e.set_downstream_process(p)

    e.mark_downstream_as_complete()
    e.is_downstream_complete()

    e.config_dependency
    e.config_capacity
示例#19
0
    def test_set_polygon(self):
        g_poly1 = gp.GeoPolygon()
        g_poly2 = gp.GeoPolygon(self._create_polygon(), self.crs_ll)
        modules.load_known_modules()
        for instance in [g_poly1, g_poly2]:

            instance.set_polygon(Polygon([self.loc2_ll]), self.crs_ll)

            nt.assert_equals(instance.polygon().num_vertices(), 1)
            nt.assert_equals(instance.crs(), self.crs_ll)
            np.testing.assert_array_almost_equal(instance.polygon().at(0),
                                                 self.loc2_ll)
            np.testing.assert_array_almost_equal(
                instance.polygon(self.crs_ll).at(0), self.loc2_ll)
            nt.assert_false(instance.is_empty())
            instance.set_polygon(Polygon([self.loc_utm]), self.crs_utm_6s)

            nt.assert_equals(instance.polygon().num_vertices(), 1)
            nt.assert_equals(instance.crs(), self.crs_utm_6s)
            np.testing.assert_array_almost_equal(instance.polygon().at(0),
                                                 self.loc_utm)
            np.testing.assert_array_almost_equal(
                instance.polygon(self.crs_utm_6s).at(0), self.loc_utm)
            nt.assert_false(instance.is_empty())

            try:
                loc_out = instance.polygon(self.crs_ll).at(0)
            except:
                # This may throw an exception regarding no conversion functor.
                # This is ok. See test_geo_polygon.cxx
                pass
            else:
                diff_loc_out_loc2_ll = np.linalg.norm(loc_out - self.loc2_ll)
                nt.assert_not_equal(
                    diff_loc_out_loc2_ll,
                    0,
                    msg=
                    "Changing the location did not clear the location cache",
                )  # This would fail if loc2_ll was cached
示例#20
0
    def test_conversion(self):
        modules.load_known_modules()

        p_ll = gp.GeoPolygon(Polygon([self.loc_ll]), self.crs_ll)
        p_utm = gp.GeoPolygon(Polygon([self.loc_utm]), self.crs_utm_6s)

        conv_loc_utm = p_ll.polygon(p_utm.crs()).at(0)
        conv_loc_ll = p_utm.polygon(p_ll.crs()).at(0)

        np.testing.assert_array_almost_equal(p_ll.polygon().at(0),
                                             conv_loc_ll,
                                             decimal=7)
        np.testing.assert_array_almost_equal(p_utm.polygon().at(0),
                                             conv_loc_utm,
                                             decimal=2)

        np.testing.assert_array_almost_equal(self.loc_ll,
                                             conv_loc_ll,
                                             decimal=7)
        np.testing.assert_array_almost_equal(self.loc_utm,
                                             conv_loc_utm,
                                             decimal=2)
示例#21
0
def test_simple_pipeline(path):
    import os

    from kwiver.sprokit.pipeline import pipeline
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline_util import bake
    from kwiver.sprokit.pipeline_util import export_

    modules.load_known_modules()

    p = bake.bake_pipe_file(path)
    r, w = os.pipe()

    name = 'graph'

    export_.export_dot(w, p, name)

    p.setup_pipeline()

    export_.export_dot(w, p, name)

    os.close(r)
    os.close(w)
示例#22
0
def test_cluster_multiplier(path):
    from kwiver.vital import config
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline_util import bake
    from kwiver.sprokit.pipeline_util import load

    blocks = load.load_cluster_file(path)

    modules.load_known_modules()

    bake.bake_cluster_file(path)
    with open(path, 'r') as fin:
        bake.bake_cluster(fin)
    info = bake.bake_cluster_blocks(blocks)

    conf = config.empty_config()

    info.type()
    info.description()
    info.create()
    info.create(conf)

    bake.register_cluster(info)
示例#23
0
    def test_convert(self):
        modules.load_known_modules()

        # First no altitude
        loc_ll = self.loc1
        crs_ll = g.SRID.lat_lon_WGS84
        loc_utm = np.array([601375.01, 4744863.31])
        crs_utm = g.SRID.UTM_WGS84_north + 18

        ll_to_utm = g.geo_conv(loc_ll, crs_ll, crs_utm)
        utm_to_ll = g.geo_conv(loc_utm, crs_utm, crs_ll)

        np.testing.assert_array_almost_equal(utm_to_ll, loc_ll, decimal=7)
        np.testing.assert_array_almost_equal(ll_to_utm, loc_utm, decimal=2)

        print(
            "Original in LL:", loc_ll, "Recovered after converting UTM->LL:", utm_to_ll
        )
        print(
            "Original in UTM:",
            loc_utm,
            "Recovered after converting LL->UTM:",
            ll_to_utm,
        )
示例#24
0
 def setUp(self):
     modules.load_known_modules()
     self.instance = ImageIO.create("SimpleImageIO")
示例#25
0
Tests for Python interface to vital::local_geo_cs

"""

import nose.tools as nt
import unittest
import numpy as np
from kwiver.vital.modules import modules
from kwiver.vital.types import (
    LocalGeoCS,
    GeoPoint,
    geodesy,
    local_geo_cs,
)

modules.load_known_modules()


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):
示例#26
0
 def test_bad_detect(self):
     modules.load_known_modules()
     detector = ImageObjectDetector.create("example_detector")
     detector.detect("Image")
示例#27
0
 def test_create(self):
     modules.load_known_modules()
     registered_detector = ImageObjectDetector.registered_names()[0]
     nose.tools.ok_(registered_detector is not None,
                     "No instance returned from the factory method")
示例#28
0
 def test_registered_names(self):
     modules.load_known_modules()
     registered_detectors = ImageObjectDetector.registered_names()
     print("All registered image object detectors")
     for detectors in registered_detectors:
         print(" " + detectors)
示例#29
0
 def test_load(self):
     from kwiver.vital.modules import modules
     modules.load_known_modules()
示例#30
0
def test_api_calls():
    from kwiver.vital.config import config
    from kwiver.sprokit.pipeline import edge
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.sprokit.pipeline import process
    from kwiver.sprokit.pipeline import process_cluster
    from kwiver.sprokit.pipeline import process_factory

    p = pipeline.Pipeline()

    proc_type1 = 'numbers'
    proc_type2 = 'print_number'
    proc_type3 = 'orphan_cluster'

    proc_name1 = 'src'
    proc_name2 = 'snk'
    proc_name3 = 'orp'

    port_name1 = 'number'
    port_name2 = 'number'

    modules.load_known_modules()

    proc1 = process_factory.create_process(proc_type1, proc_name1)

    conf_name = 'output'

    c = config.empty_config()

    c.set_value(conf_name, 'test-python-pipeline-api_calls-print_number.txt')
    proc2 = process_factory.create_process(proc_type2, proc_name2, c)

    proc3 = process_factory.create_process(proc_type3, proc_name3)

    p.add_process(proc1)
    p.add_process(proc2)
    p.add_process(proc3)
    p.connect(proc_name1, port_name1, proc_name2, port_name2)
    p.process_names()
    p.process_by_name(proc_name1)
    p.cluster_names()
    p.cluster_by_name(proc_name3)
    p.connections_from_addr(proc_name1, port_name1)
    p.connection_to_addr(proc_name2, port_name2)

    p.disconnect(proc_name1, port_name1, proc_name2, port_name2)
    p.remove_process(proc_name1)
    p.remove_process(proc_name3)

    # Restore the pipeline so that setup_pipeline works.
    p.add_process(proc1)
    p.connect(proc_name1, port_name1, proc_name2, port_name2)

    p.setup_pipeline()

    p.upstream_for_process(proc_name2)
    p.upstream_for_port(proc_name2, port_name2)
    p.downstream_for_process(proc_name1)
    p.downstream_for_port(proc_name1, port_name1)
    p.sender_for_port(proc_name2, port_name2)
    p.receivers_for_port(proc_name1, port_name1)
    p.edge_for_connection(proc_name1, port_name1, proc_name2, port_name2)
    p.input_edges_for_process(proc_name2)
    p.input_edge_for_port(proc_name2, port_name2)
    p.output_edges_for_process(proc_name1)
    p.output_edges_for_port(proc_name1, port_name1)

    p.is_setup()
    p.setup_successful()

    c = config.empty_config()

    p.reconfigure(c)

    p.reset()