23 import matplotlib.pyplot
as plt
27 from os.path
import expanduser
28 from app_error_exception
import AppError
29 from rapp_platform_ros_communications.srv
import (
30 createOntologyAliasSrv,
31 createOntologyAliasSrvRequest,
32 createOntologyAliasSrvResponse,
33 registerImageToOntologySrv,
34 registerImageToOntologySrvResponse,
35 registerImageToOntologySrvRequest,
36 registerImageObjectToOntologySrv,
37 registerImageObjectToOntologySrvRequest,
38 registerImageObjectToOntologySrvResponse
56 res = registerImageToOntologySrvResponse()
58 baseDestinationFolder = rospy.get_param(
"user_images_folder")+req.username+
"_"+ontologyAlias+
"/"
60 ontologyName=ontologyName.split(
'#')[1]
62 baseDestinationFolderUserAdjusted=expanduser(
"~")+baseDestinationFolder
63 print baseDestinationFolderUserAdjusted
64 if not os.path.exists(baseDestinationFolderUserAdjusted):
65 os.makedirs(baseDestinationFolderUserAdjusted)
67 shutil.copy(req.imagePath, baseDestinationFolderUserAdjusted+ontologyName)
68 res.object_entry=ontologyName
72 res.trace.append(
"IndexError: " +str(e))
73 res.error=
"IndexError: "+str(e)
77 res.trace.append(
"IOError: "+str(e))
78 res.error=
"IOError: "+str(e)
80 AppError.passErrorToRosSrv(e,res)
83 res.trace.append(
'"KeyError, probably caffe class does not exist or no ontology equivalent exists for "%s"' % str(e))
84 res.error=
'"KeyError, probably caffe class does not exist or no ontology equivalent exists for "%s"' % str(e)
94 serv_topic = rospy.get_param(
'rapp_knowrob_wrapper_create_ontology_alias')
95 knowrob_service = rospy.ServiceProxy(serv_topic, createOntologyAliasSrv)
96 createOntologyAliasReq = createOntologyAliasSrvRequest()
97 createOntologyAliasReq.username=username
98 createOntologyAliasResponse = knowrob_service(createOntologyAliasReq)
99 if(createOntologyAliasResponse.success!=
True):
100 raise AppError(createOntologyAliasResponse.error, createOntologyAliasResponse.trace)
101 return createOntologyAliasResponse.ontology_alias
110 serv_topic = rospy.get_param(
'rapp_knowrob_wrapper_register_image_object_to_ontology')
111 knowrob_service = rospy.ServiceProxy(serv_topic, registerImageObjectToOntologySrv)
112 registerImageObjectToOntologyReq = registerImageObjectToOntologySrvRequest()
114 registerImageObjectToOntologyReq.image_path=baseDestinationFolder
115 registerImageObjectToOntologyReq.caffe_class=req.caffeClass
116 registerImageObjectToOntologyReq.timestamp=int(time.time())
117 registerImageObjectToOntologyReq.object_ontology_class=req.ontologyClass
118 registerImageObjectToOntologyResponse = knowrob_service(registerImageObjectToOntologyReq)
119 if(registerImageObjectToOntologyResponse.success!=
True):
120 registerImageObjectToOntologyResponse.trace.append(
"Error in registering the image to the ontology")
121 raise AppError(registerImageObjectToOntologyResponse.error+
"Error in registering the image to the ontology",registerImageObjectToOntologyResponse.trace)
122 return registerImageObjectToOntologyResponse.object_entry
def registerImage
Implements the getCloudAgentServiceTypeAndHostPort service main function.
def getUserOntologyAlias
Gets the users ontology alias and if it doesnt exist it creates it.
def registerImageToOntology
Calls the knowrob_wrapper service that registers the image to the ontology.
Contains the necessary functions for registering images to the ontology.
Exception compliant with the ros error and trace srvs.