使用点云库从C++中的 URL 读取文件,而不是本地文件

Read files from URL in C++ instead of local files using Point Cloud Library

本文关键字:文件 读取 URL 中的 C++      更新时间:2023-10-16

我是点云库 (PCL( 的新手,对指针如何工作C++了解有限。虽然我们可以从文件加载文件并可视化它(使用本教程(,但我们如何从 HTTP URL 读取它?

int main () {
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud);
pcl::visualization::CloudViewer viewer("Cloud Viewer");
//blocks until the cloud is actually rendered
viewer.showCloud(cloud);
//use the following functions to get access to the underlying more advanced/powerful
//PCLVisualizer
while (!viewer.wasStopped ())
{
}
return 0;
}

我不知道PCL 是否直接执行此操作,但您可以使用 cpr 或 urdl C++库将文件下载到本地临时文件,或者实际处理流。

Urdl 示例:

// For urdl::url.
#include <urdl/url.hpp>
// etc...    
urdl::url url("http://somehost/path");
urdl::istream is("http://somehost/path");

并且可以直接使用此 iStream(如果 PCL 支持(,也可以将流上的数据写入文件。

使用 cpr 的示例程序(又名 C++ 请求;基于 C 库libcurl(:

#include <cpr/cpr.h>
int main(int argc, char** argv) {
auto r = cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
cpr::Authentication{"user", "pass"},
cpr::Parameters{{"anon", "true"}, {"key", "value"}});
r.status_code;                  // 200
r.header["content-type"];       // application/json; charset=utf-8
r.text;                         // JSON text string
}

(摘自CPR官方网站(