def declare_cells(_p): """ Implement the virtual function from the base class Only cells from which something is forwarded have to be declared """ cells = {} cells['throttle'] = ecto.TrueEveryN("Throttle", n=1) cells['mat2image'] = ecto_ros.Mat2Image("Mat2Image") cells['subscribed_mat2image'] = ecto.If( "Subscribed Mat2Image", input_tendril_name="has_subscribers", cell=cells['mat2image']) cells['throttled_mat2image'] = ecto.If( "Throttled Mat2Image", input_tendril_name="throttle", cell=cells['subscribed_mat2image']) cells['publisher'] = ecto_sensor_msgs.Publisher_Image( "Publisher", topic_name="/images/candidate_beans", queue_size=2, latched=True) cells['throttled_publisher'] = ecto.If("Throttled Publisher", input_tendril_name="throttle", cell=cells['publisher']) subscribers_input, subscribers_output = \ ecto.EntangledPair(value=cells['throttled_mat2image'].inputs.at('has_subscribers'), source_name="Has Subscribers Input", sink_name="Has Subscribers Output") cells['subscribers_input'] = subscribers_input cells['subscribers_output'] = subscribers_output return cells
def connect_ros_image(self): frame_id_str = 'camera_optical_frame' self.image2ros = ecto_ros.Mat2Image( frame_id=frame_id_str, encoding='bgr8') self.depth2ros = ecto_ros.Mat2Image( frame_id=frame_id_str, encoding='16UC1') self.image_publisher = Publisher_Image(topic_name='/image') self.depth_publisher = Publisher_Image(topic_name='/depth') self.graph += [ self.observation_renderer['image'] >> self.image2ros['image'], self.observation_renderer['depth'] >> self.depth2ros['image'], self.observation_renderer['depth'] >> self.depth2point_cloud_ros['image'], self.image2ros['image'] >> self.image_publisher['input'], self.depth2ros['image'] >> self.depth_publisher['input'], ]
def do_ecto(device_id=0, frame_id='base'): video_capture = highgui.VideoCapture('Video Camera', video_device=device_id) mat2image = ecto_ros.Mat2Image(frame_id=frame_id, encoding='bgr8') pub_rgb = ImagePub("image pub", topic_name='image') graph = [ video_capture["image"] >> mat2image["image"], mat2image["image"] >> pub_rgb["input"] ] plasm = ecto.Plasm() plasm.connect(graph) sched = ecto.schedulers.Threadpool(plasm) sched.execute()
def configure(self, p, _i, _o): feature_params = self._parameters.get("feature", False) if not feature_params: raise RuntimeError("You must supply feature_descriptor parameters for TOD.") # merge it with the subtype feature_descriptor_params = { 'feature': feature_params, 'descriptor': self._parameters.get('descriptor', {}) } from object_recognition.tod import merge_dict feature_descriptor_params = merge_dict(feature_descriptor_params, self._submethod) self.feature_descriptor = FeatureDescriptor(json_params=json_helper.dict_to_cpp_json_str(feature_descriptor_params)) self.descriptor_matcher = tod_detection.DescriptorMatcher("Matcher", search_json_params=json_helper.dict_to_cpp_json_str(self._parameters['search']), model_documents=self._model_documents) self.message_cvt = ecto_ros.Mat2Image() guess_params = self._parameters['guess'].copy() guess_params['visualize'] = self._visualize self.guess_generator = tod_detection.GuessGenerator("Guess Gen", **guess_params)
def do_ecto(): # ecto options parser = argparse.ArgumentParser( description='Publish images from directory.') scheduler_options(parser) args = parser.parse_args() #this will read all images in the path path = '/home/sam/Code/vision/VOCdevkit/VOC2012/JPEGImages' images = ImageReader(path=os.path.expanduser(path)) mat2image = ecto_ros.Mat2Image(encoding='rgb8') pub_rgb = ImagePub("image_pub", topic_name='/camera/rgb/image_raw') display = imshow(name='image', waitKey=5000) plasm = ecto.Plasm() plasm.connect( images['image'] >> mat2image['image'], images['image'] >> display['image'], mat2image['image'] >> pub_rgb['input'], ) ecto.view_plasm(plasm) run_plasm(args, plasm, locals=vars())
print LinemodDetectionPipeline.type_name() object_ids = ['whoolite', 'tilex'] model_documents = Models(object_db, object_ids, LinemodDetectionPipeline.type_name(), json_helper.dict_to_cpp_json_str({})) print len(model_documents) detector = Detector(model_documents=model_documents, db=object_db, threshold=90) #connect up the pose_est plasm.connect(source['image'] >> detector['image'], source['depth'] >> detector['depth']) plasm.connect(source['image'] >> imshow(name='source')[:]) if 0: import ecto_ros import ecto_ros.ecto_sensor_msgs import sys ecto_ros.init(sys.argv, "image_pub") mat2image = ecto_ros.Mat2Image(frame_id='base', encoding='bgr8') pub_rgb = ecto_ros.ecto_sensor_msgs.Publisher_Image( "image pub", topic_name='linemod_image') plasm.connect(detector['image'] >> mat2image[:], mat2image[:] >> pub_rgb[:]) else: plasm.connect(detector['image'] >> imshow(name='result')[:]) run_plasm(options, plasm, locals=vars())