0
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Path.h>
#include <Poco/URI.h>
#include <iostream>
#include <string>
#include <Poco/JSON/JSON.h>
#include <Poco/JSON/Parser.h>
#include <Poco/Net/HTMLForm.h>

#include <Windows.h>
#include <vector>

#include <opencv2/opencv.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>

#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_sinks.h>
#include <chrono>
#include <typeinfo>
#include <string>

#include "base64.cpp"

std::string host="127.0.0.1";
int port =2000;

std::string path="/images/"
Poco::Net::HTTPClientSession session(host, port);
session.setKeepAlive(true);

Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_POST, path);

std::string m_files_path=
"C:/Users/syste/OneDrive/Pictures/Screenshots/*.png";

std::vector<std::string> imageFiles;
cv::glob(m_files_path, imageFiles);

cv::Mat image = cv::imread(imageFiles[0]);

std::vector<unsigned char> buff;

cv::imencode(".png", image, buff);
auto base64_png = reinterpret_cast<const unsigned char*>(buff.data());

std::string body1 = base64_encode(base64_png, buff.size());

obj.set("photo1", body1);

std::stringstream ss;
obj.stringify(ss);

std::string body;
body = ss.str();

req.setContentType("application/json");
req.setContentLength(body.length());

session.sendRequest(req)<<body;

I am able to send image from cpp Client using poco server but the image taking more time to converting imencode and using base64 encode and making as stringify. So is any another method for sending data using post request of poco cpp.

If any faster methods for sending image suggest me to move forward.

In my case processing 1 image taking 0.45-0.55 seconds. but i want to send atleast 60 images per second.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
REDDY
  • 49
  • 5
  • 1
    you can send binary data, right? then **get rid of** the base64 nonsense, and especially the JSON nonsense -- you already have the images in compressed form, so simply send those as is. it's all HTTP, right? then you can send PNG files. -- no need for OpenCV here *at all* – Christoph Rackwitz Jun 06 '22 at 11:41
  • obj.set("photo1", buff); like this – REDDY Jun 08 '22 at 11:25
  • the entire imread-imencode piece needs to be removed. it is pointless. you could just as well read the file itself. you'd get the same result, without superfluous steps. – Christoph Rackwitz Jun 08 '22 at 11:41
  • please use a search engine: `addPart` https://stackoverflow.com/questions/13968134/poco-how-to-upload-image-to-webser-using-poco-in-c (I don't know poco, I'm only here because you tagged `OpenCV` even though this has nothing to do with OpenCV) – Christoph Rackwitz Jun 08 '22 at 11:42
  • if you mind give some example – REDDY Jun 09 '22 at 03:57
  • The Above code is minimal code for sending image data but if I use live camera streaming data then I want OPENCV , Yes in above comments suggestions working for me ,even though from server side I want to access like key pair value otherwise data goes wrong. – REDDY Jun 10 '22 at 02:53

0 Answers0