使用openCV从AmazonS3读取图像

Using openCV to read an image from Amazon S3

本文关键字:读取 图像 AmazonS3 openCV 使用      更新时间:2023-10-16

我知道有多个C++库可以使用cURL访问AmazonS3中的数据。使用它们,我可以将图像下载到本地机器上,将其读取到OpenCV中,并删除原始文件。

但是,我想知道是否可以直接将S3中的图像读取到OpenCV中,比如Mat对象。

有人能帮我完成这件事吗?

使用cv::imdecode,它将把内存中的一些图像数据(png、jpeg等)加载到一个矩阵中。

// Suppose that a std::vector<char> contains the data loaded by Curl.
std::vector<char> data;
// The template<typename T> explicit cv::Mat::Mat(const std::vector<T>& vec)
// constructor gives this vector a cv::Mat header.
cv::Mat data_mat(data);
// Now use cv::imdecode to decode the image to a BGR matrix.
cv::Mat image(cv::imdecode(data_mat));

所以,就Poco方面而言,这就是我必须做的。

std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri));StreamCopier::copyToString(*pStr.get(), str);

这将在没有任何中间存储的情况下将图像从所提供的URI获取到字符串str中。其余的正如克里斯托夫所解释的。