#!/usr/bin/env python
from object_recognition.common.io.source import _assert_source_interface
from object_recognition.common.io.source import Source

import argparse
parser = argparse.ArgumentParser(description='An source reader.')
Source.add_arguments(parser)
parser.print_help()

#test default args
args = parser.parse_args()
source = Source.parse_arguments(args)
_assert_source_interface(source)
print source.__class__.__name__

#assert 'KinectReader' == source.__class__.__name__

#test a bad bag
args = parser.parse_args(['--ros_bag','non_existant.bag'])
try:
    source = Source.parse_arguments(args)
except RuntimeError,e:
    print str(e)
    assert 'non_existant.bag does not exist.' in str(e)

#test an existing bag
with open('a_test.bag','w') as f:
    f.write('\ntest\n')

args = parser.parse_args(['--ros_bag','a_test.bag'])
#note that the bag hasn't been opened here.
#!/usr/bin/env python
from object_recognition.common.io.ros.source import BagReader
from object_recognition.common.io.source import _assert_source_interface
br = BagReader()
print br.__doc__
assert 'image_message' in br.__doc__
assert 'depth' in br.__doc__
assert 'image' in br.__doc__
assert 'K' in br.__doc__

#verify some types.
assert 'boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const>' == br.outputs.at('image_message').type_name

#this should pass our interface check
_assert_source_interface(br)


#test the bag file name parameter
br = BagReader(bag='testy.bag')
assert br.params.bag == 'testy.bag'
assert br._source.params.bag == 'testy.bag'
_assert_source_interface(br)
Example #3
0
#!/usr/bin/env python
from object_recognition.common.io.source import _assert_source_interface

#test that names have to be correct.
try:
    from ecto import And
    a = And()
    _assert_source_interface(a)
    assert False == "Should not have gotten here."
except NotImplementedError,e:
    assert "Must have an output named K" in str(e)


import ecto
outputs = ecto.Tendrils()
outputs.declare("image","an image", "image image")
outputs.declare("depth","a depth map", "depth depth")
outputs.declare("K","a camera matrix", "eye(3)")
outputs.declare("points3d","A matrix of 3 vectors", "Mat(N,3)")

class Source(object):
    pass
kr = Source()
kr.outputs = outputs
try:
    _assert_source_interface(kr)
    assert False == "Should not have gotten here."
except NotImplementedError,e:
    assert "This cells output at K has type boost::python::api::object" in str(e)

Example #4
0
#!/usr/bin/env python
from object_recognition.common.io.ros.source import BagReader
from object_recognition.common.io.source import _assert_source_interface

br = BagReader()
print br.__doc__
assert 'image_message' in br.__doc__
assert 'depth' in br.__doc__
assert 'image' in br.__doc__
assert 'K' in br.__doc__

#verify some types.
assert 'boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const>' == br.outputs.at(
    'image_message').type_name

#this should pass our interface check
_assert_source_interface(br)

#test the bag file name parameter
br = BagReader(bag='testy.bag')
assert br.params.bag == 'testy.bag'
assert br._source.params.bag == 'testy.bag'
_assert_source_interface(br)