1 #ifndef RAPP_CLOUD_OBJECT_RECOGNITION
2 #define RAPP_CLOUD_OBJECT_RECOGNITION
22 const std::shared_ptr<rapp::object::picture> image,
23 std::function<
void(std::string)> callback,
31 boost::property_tree::ptree tree;
32 tree.put(
"file", fname);
34 boost::property_tree::write_json(ss, tree,
false);
35 post_ =
"--" + boundary +
"\r\n"
36 +
"Content-Disposition: form-data; name=\"json\"\r\n\r\n"
38 post_ +=
"--"+boundary+
"\r\n"
39 +
"Content-Disposition: form-data; name=\"file_uri\"; filename=\""+fname+
"\"\r\n"
40 +
"Content-Type: image/"+image->type()+
"\r\n"
41 +
"Content-Transfer-Encoding: binary\r\n\r\n";
43 auto imagebytes = image->bytearray();
44 post_.insert(
post_.end(), imagebytes.begin(), imagebytes.end());
46 post_ +=
"--"+boundary+
"--";
47 header_ =
"POST /hop/object_recognition_caffe HTTP/1.1\r\n";
48 header_ +=
"Content-Type: multipart/form-data; boundary="+boundary+
"\r\n\r\n";
57 std::stringstream ss(json);
58 std::string object_class;
60 boost::property_tree::ptree tree;
61 boost::property_tree::read_json(ss, tree);
62 for (
auto child : tree.get_child(
"object_class")) {
63 object_class = child.second.get_value<std::string>();
66 for (
auto child : tree.get_child(
"error")) {
67 const std::string value = child.second.get_value<std::string>();
69 std::cerr <<
"object_recognition JSON error: " << value << std::endl;
73 catch(boost::property_tree::json_parser::json_parser_error & je) {
74 std::cerr <<
"object_recognition::handle_reply Error parsing: "
75 << je.filename() <<
" on line: " << je.line() << std::endl;
76 std::cerr << je.message() << std::endl;
object_recognition(const std::shared_ptr< rapp::object::picture > image, std::function< void(std::string)> callback, std::string token)
Constructor.
std::string header_
Header that will be used.
std::string random_boundary() const
Create a random boundary for the multipart/form in HTTP.
std::function< void(std::string)> delegate__
The callback called upon completion of receiving the detected faces.
std::string post_
Actual post Data.
void handle_reply(std::string json)
handle the rapp-platform JSON reply
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
base class for asynchronous http websockets used for connecting to cloud services ...
recognize object from an image