1 #ifndef RAPP_CLOUD_HUMAN_DETECTION
2 #define RAPP_CLOUD_HUMAN_DETECTION
23 const std::shared_ptr<rapp::object::picture> image,
24 std::function<
void(std::vector<rapp::object::human>)> callback,
32 boost::property_tree::ptree tree;
33 tree.put(
"file", fname);
35 boost::property_tree::write_json(ss, tree,
false);
36 post_ =
"--" + boundary +
"\r\n"
37 +
"Content-Disposition: form-data; name=\"json\"\r\n\r\n"
39 post_ +=
"--"+boundary+
"\r\n"
40 +
"Content-Disposition: form-data; name=\"file_uri\"; filename=\""+fname+
"\"\r\n"
41 +
"Content-Type: image/"+image->type()+
"\r\n"
42 +
"Content-Transfer-Encoding: binary\r\n\r\n";
44 auto imagebytes = image->bytearray();
45 post_.insert(
post_.end(), imagebytes.begin(), imagebytes.end());
47 post_ +=
"--"+boundary+
"--";
48 header_ =
"POST /hop/human_detection HTTP/1.1\r\n";
49 header_ +=
"Content-Type: multipart/form-data; boundary="+boundary+
"\r\n\r\n";
58 std::stringstream ss(json);
59 std::vector<rapp::object::human> humans;
61 boost::property_tree::ptree tree;
62 boost::property_tree::read_json(ss, tree);
64 for (
auto child : tree.get_child(
"humans")) {
65 std::pair<float,float> up_left;
66 std::pair<float,float> down_right;
68 for (
auto iter = child.second.begin(); iter!= child.second.end(); ++iter) {
69 if (iter->first ==
"up_left_point") {
70 for (
auto it : iter->second) {
71 if (it.first ==
"x") {
72 std::get<0>(up_left) = it.second.get_value<
float>();
74 else if (it.first ==
"y") {
75 std::get<1>(up_left) = it.second.get_value<
float>();
79 else if (iter->first ==
"down_right_point") {
80 for (
auto it : iter->second) {
81 if ( it.first ==
"x" ) {
82 std::get<0>(down_right) = it.second.get_value<
float>();
84 else if (it.first ==
"y") {
85 std::get<1>(down_right) = it.second.get_value<
float>();
92 std::get<0>(down_right),
93 std::get<1>(down_right)));
96 for (
auto child : tree.get_child(
"error")) {
97 const std::string value = child.second.get_value<std::string>();
99 std::cerr <<
"human_detection JSON error: " << value << std::endl;
103 catch(boost::property_tree::json_parser::json_parser_error & je) {
104 std::cerr <<
"human_detection::handle_reply Error parsing: "
105 << je.filename() <<
" on line: " << je.line() << std::endl;
106 std::cerr << je.message() << std::endl;
112 std::function<void(std::vector<rapp::object::human>)>
delegate__;
std::string header_
Header that will be used.
human_detection(const std::shared_ptr< rapp::object::picture > image, std::function< void(std::vector< rapp::object::human >)> callback, std::string token)
Constructor.
std::string random_boundary() const
Create a random boundary for the multipart/form in HTTP.
void handle_reply(std::string json)
handle the rapp-platform JSON reply
describes human coordinates
std::string post_
Actual post Data.
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 ...
detect humans in an image
std::function< void(std::vector< rapp::object::human >)> delegate__
The callback called upon completion of receiving the detected faces.