RAPP Platform  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Classes Namespaces Files Functions Variables Macros
caffe_wrapper.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- encode: utf-8 -*-
3 
4 #Copyright 2015 RAPP
5 
6 #Licensed under the Apache License, Version 2.0 (the "License");
7 #you may not use this file except in compliance with the License.
8 #You may obtain a copy of the License at
9 
10  #http://www.apache.org/licenses/LICENSE-2.0
11 
12 #Unless required by applicable law or agreed to in writing, software
13 #distributed under the License is distributed on an "AS IS" BASIS,
14 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #See the License for the specific language governing permissions and
16 #limitations under the License.
17 
18 # Author: Athanassios Kintsakis
19 # contact: akintsakis@issel.ee.auth.gr
20 
21 import rospy
22 import sys
23 
24 from image_classification import ImageClassification
25 from ontology_class_bridge import OntologyClassBridge
26 from image_registration_to_ontology import ImageRegistrationToOntology
27 
28 from rapp_platform_ros_communications.srv import (
29  imageClassificationSrv,
30  imageClassificationSrvResponse,
31  ontologyClassBridgeSrv,
32  ontologyClassBridgeSrvResponse,
33  registerImageToOntologySrv,
34  registerImageToOntologySrvResponse
35  )
36 
37 from rapp_platform_ros_communications.msg import (
38  StringArrayMsg
39  )
40 
41 from std_msgs.msg import (
42  String
43  )
44 
45 ## @class RappCaffeWrapper
46 # @brief The RappCaffeWrapper ros node
48 
49  ## @brief Default contructor
50  #
51  # Waits for services the node depends on and declares the callbacks of the node's services
52  def __init__(self):
53 
54  # Dependencies
55  self.serv_topic = rospy.get_param('rapp_knowrob_wrapper_create_ontology_alias')
56  if(not self.serv_topic):
57  rospy.logerror("rapp_knowrob_wrapper_create_ontology_alias param not found")
58  rospy.wait_for_service(self.serv_topic)
59 
60  self.serv_topic = rospy.get_param('rapp_knowrob_wrapper_register_image_object_to_ontology')
61  if(not self.serv_topic):
62  rospy.logerror("rapp_knowrob_wrapper_register_image_object_to_ontology param not found")
63  rospy.wait_for_service(self.serv_topic)
64 
65  #Declare Callbacks
66  self.serv_topic = rospy.get_param("rapp_caffe_wrapper_image_classification")
67  if(not self.serv_topic):
68  rospy.logerror("rapp_caffe_wrapper_image_classification")
69  self.serv=rospy.Service(self.serv_topic, imageClassificationSrv, self.imageClassificationDataHandler)
70 
71  self.serv_topic = rospy.get_param("rapp_caffe_wrapper_get_ontology_class_equivalent")
72  if(not self.serv_topic):
73  rospy.logerror("rapp_caffe_wrapper_get_ontology_class_equivalent")
74  self.serv=rospy.Service(self.serv_topic, ontologyClassBridgeSrv, self.ontologyClassBridgeDataHandler)
75 
76  self.serv_topic = rospy.get_param("rapp_caffe_wrapper_register_image_to_ontology")
77  if(not self.serv_topic):
78  rospy.logerror("rapp_caffe_wrapper_register_image_to_ontology")
79  self.serv=rospy.Service(self.serv_topic, registerImageToOntologySrv, self.registerImageToOntologyDataHandler)
80 
81  ## @brief The imageClassificationSrv service callback
82  # @param req [rapp_platform_ros_communications::imageClassificationSrvRequest::Request&] The ROS service request
83  # @return res [rapp_platform_ros_communications::imageClassificationSrvResponse::Response&] The ROS service response
85  res = imageClassificationSrvResponse()
86  it = ImageClassification()
87  res=it.classifyImage(req)
88  return res
89 
90  ## @brief The ontologyClassBridgeSrv service callback
91  # @param req [rapp_platform_ros_communications::ontologyClassBridgeSrvRequest::Request&] The ROS service request
92  # @return res [rapp_platform_ros_communications::ontologyClassBridgeSrvResponse::Response&] The ROS service response
94  res = ontologyClassBridgeSrvResponse()
95  it = OntologyClassBridge()
96  res=it.getOntologyClassEquivalent(req)
97  return res
98 
99  ## @brief The registerImageToOntologySrv service callback
100  # @param req [rapp_platform_ros_communications::registerImageToOntologySrvRequest::Request&] The ROS service request
101  # @return res [rapp_platform_ros_communications::registerImageToOntologySrvResponse::Response&] The ROS service response
103  res = registerImageToOntologySrvResponse()
105  res=it.registerImage(req)
106  return res
107 
The RappCaffeWrapper ros node.
def ontologyClassBridgeDataHandler
The ontologyClassBridgeSrv service callback.
Contains the necessary functions for translating caffe classes to ontology classes.
Contains the necessary functions for registering images to the ontology.
def __init__
Default contructor.
def imageClassificationDataHandler
The imageClassificationSrv service callback.
Contains the necessary functions for classifying an images and requesting registration to the ontolog...
def registerImageToOntologyDataHandler
The registerImageToOntologySrv service callback.