1 #ifndef RAPP_SERVICE_CLOUD_QRDETECTOR
2 #define RAPP_SERVICE_CLOUD_QRDETECTOR
23 const std::shared_ptr<rapp::object::picture> image,
24 const std::string token,
25 std::function<
void(std::vector<rapp::object::qr_code>)> 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/qr_detection HTTP/1.1\r\n";
49 header_ +=
"Content-Type: multipart/form-data; boundary="+boundary+
"\r\n\r\n";
59 std::stringstream ss(json);
60 std::vector<rapp::object::qr_code> qrCodes;
62 boost::property_tree::ptree tree;
63 boost::property_tree::read_json(ss, tree);
64 for (
auto child : tree.get_child(
"qr_centers")) {
65 std::tuple<float,float,std::string> qrcode;
66 for (
auto iter = child.second.begin(); iter != child.second.end(); ++iter) {
67 if (iter->first ==
"x") {
68 std::get<0>(qrcode) = iter->second.get_value<
float>();
70 else if (iter->first ==
"y") {
71 std::get<1>(qrcode) = iter->second.get_value<
float>();
73 else if (iter->first ==
"message") {
74 std::get<2>(qrcode) = iter->second.get_value<std::string>();
79 std::get<2>(qrcode)));
82 for (
auto child : tree.get_child(
"error")) {
83 const std::string value = child.second.get_value<std::string>();
85 std::cerr <<
"qr_detection JSON error: " << value << std::endl;
89 catch(boost::property_tree::json_parser::json_parser_error & je) {
90 std::cerr <<
"qr_detection::handle_reply Error parsing: "
91 << je.filename() <<
" on line: " << je.line() << std::endl;
92 std::cerr << je.message() << std::endl;
98 std::function<void(std::vector<rapp::object::qr_code>)>
delegate__;
std::function< void(std::vector< rapp::object::qr_code >)> delegate__
The callback called upon completion of receiving the detected faces.
std::string header_
Header that will be used.
std::string random_boundary() const
Create a random boundary for the multipart/form in HTTP.
qr_detection(const std::shared_ptr< rapp::object::picture > image, const std::string token, std::function< void(std::vector< rapp::object::qr_code >)> callback)
Constructor.
std::string post_
Actual post Data.
Asynchronous Service which will request the cloud to detect QR codes.
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
void handle_reply(std::string json)
handle the rapp-platform JSON reply
base class for asynchronous http websockets used for connecting to cloud services ...