2016-04-21 19 views
3

我有一個使用Qt和openCV的圖像處理應用程序。如何使用POCO庫將C++對象轉移到Web服務

對於每一幀,我應該發送捕獲的cv :: Mat圖像對象到服務器來處理它並得到結果。

我應該使用REST架構來實現其低負載。

什麼是我應該用來發送cv :: Mat到服務器的工具。

我正在使用POCO來實現便攜性。

我尋求最輕的解決方案來做到這一點,我需要一秒鐘內服務器處理10幀的最低速度。

我的意思是,有沒有一種方法可以將C++對象傳遞給服務器而無需顯式序列化?

+0

1)序列化圖像串(用'imencode'並最終base64編碼很容易做到),2)發送通過上服務器解碼REST 3)串圖像(base64解碼和'imdecode')4)現在你有你的圖像服務器端。 – Miki

+0

謝謝,爲什麼你沒有把它作爲答案?問題在於,我仍然是POCO的初學者,並且在POCO中發送一個cv :: Mat的完整示例。 – ProEns08

+0

因爲完整的答案會過於寬泛(如問題; D)。我只是給你一些指示。您可以輕鬆地找到每個步驟的很多信息 – Miki

回答

2

編輯

隨着POCO庫,你可以在這個答案一看:HttpRequest PUT content in poco library。他正在發送文件ifstream

在這個答案中,你可以檢查如何將cv::Mat轉換成istreamOpenCV cv::Mat to std::ifstream for base64 encoding

最後,由於多態性,istream被隱含轉換爲ifstream。


您可以使用C++ Rest SDK。 PUT命令的代碼示例。

Source of code

Library Github where you can find the full documentation.

#include <http_client.h> 
#include <filestream.h> 
#include <iostream> 
#include <sstream> 

using namespace web::http; 
using namespace web::http::client; 

// Upload a file to an HTTP server. 
pplx::task<void> UploadFileToHttpServerAsync() 
{ 
    using concurrency::streams::file_stream; 
    using concurrency::streams::basic_istream; 

    // To run this example, you must have a file named myfile.txt in the current folder. 
    // Alternatively, you can use the following code to create a stream from a text string. 
    // std::string s("abcdefg"); 
    // auto ss = concurrency::streams::stringstream::open_istream(s); 

    // Open stream to file. 
    return file_stream<unsigned char>::open_istream(L"myfile.txt").then([](pplx::task<basic_istream<unsigned char>> previousTask) 
    { 
     try 
     { 
      auto fileStream = previousTask.get(); 

      // Make HTTP request with the file stream as the body. 
      http_client client(L"http://www.fourthcoffee.com"); 
      return client.request(methods::PUT, L"myfile", fileStream).then([fileStream](pplx::task<http_response> previousTask) 
      { 
       fileStream.close(); 

       std::wostringstream ss; 
       try 
       { 
        auto response = previousTask.get(); 
        ss << L"Server returned returned status code " << response.status_code() << L"." << std::endl; 
       } 
       catch (const http_exception& e) 
       { 
        ss << e.what() << std::endl; 
       } 
       std::wcout << ss.str(); 
      }); 
     } 
     catch (const std::system_error& e) 
     { 
      std::wostringstream ss; 
      ss << e.what() << std::endl; 
      std::wcout << ss.str(); 

      // Return an empty task. 
      return pplx::task_from_result(); 
     } 
    }); 

    /* Sample output: 
    The request must be resent 
    */ 
} 
+0

非常感謝,+ 1.但是我在編輯時使用POCO來實現便攜性。 – ProEns08

+0

我編輯了我的答案,看起來鏈接的答案有你所需要的。希望能幫助到你。 –

+0

謝謝,但在這個例子中,他正在發送一個文件。我搜索發送一個cv :: Mat或一個純粹的C++對象。 – ProEns08

相關問題