pcl::HarrisKeypoint2D

本文提供了一个使用Point Cloud Library (PCL)进行Harris特征点检测的C++示例程序。该示例通过从GIMP图像数据创建点云,并应用HarrisKeypoint2D类来检测关键点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从github中找到了一个例子,特分享如下:


#define _CRT_SECURE_NO_WARNINGS
#include <pcl/keypoints/harris_2d.h>
#include <pcl/point_types.h>

static const struct {
 unsigned int   width;
 unsigned int   height;
 unsigned int   bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
 unsigned char  pixel_data[9 * 9 * 3 + 1];
} gimp_image = {
 9, 9, 3,
 "\377\346\307\262\377\274\221\201\377\333\340\334\333\340\334\330\335\331"
 "\261\265\262\264\260\260\265\272\300\273\302\273\272\277\271\306\313\305"
 "\314\316\311\316\320\313\316\316\314\326\326\324\334\336\333\335\337\334"
 "\262\263\255\243\242\235\251\250\243\257\253\250\265\261\256\265\260\255"
 "\273\266\263\276\272\271\303\277\276\255\250\244\214\207\203\213\203\200"
 "\216\204\202\225\213\211\224\212\211\221\207\206\217\205\204\226\214\213"
 "\272\270\254\242\236\222\246\234\222\245\227\214\223\177v\235\202{\211lh"
 "{\\Y\202dd\317\317\305\300\276\261\274\264\251\272\256\240\263\237\224\273"
 "\240\225\246\205~\214ga\206^^\332\335\322\324\326\311\317\314\275\314\305"
 "\263\316\276\256\330\301\257\331\271\254\267\217\205\204TP\332\340\326\335"
 "\341\323\334\337\316\334\332\305\334\324\275\345\323\275\344\310\263\321"
 "\254\234\261\177v\330\335\326\334\342\330\341\345\327\337\342\315\341\337"
 "\310\343\334\300\346\325\273\346\307\262\274\221\201",
};


int main(int argc, char *argv[])
{

 typedef pcl::PointCloud<pcl::PointXYZI> PointCloudTXYZI;

 PointCloudTXYZI::Ptr cloud(new PointCloudTXYZI);
 for (int i = 0, ie = gimp_image.width * gimp_image.height * gimp_image.bytes_per_pixel; i < ie; i += gimp_image.bytes_per_pixel)
 {
  const unsigned char* r = &gimp_image.pixel_data[i];
  const unsigned char* g = &gimp_image.pixel_data[i + 1];
  const unsigned char* b = &gimp_image.pixel_data[i + 2];

  pcl::PointXYZI point;
  point.x = i / gimp_image.bytes_per_pixel - i / (gimp_image.width*gimp_image.bytes_per_pixel)*gimp_image.width;
  point.y = i / (gimp_image.width*gimp_image.bytes_per_pixel);
  point.z = 1;

  point.intensity = (299 * (int)*r + 587 * (int)*g + 114 * (int)*b) * 0.001f;
  cloud->push_back(point);
 }

 cloud->is_dense = true;
 cloud->height = gimp_image.height;
 cloud->width = gimp_image.width;

 int winWidth = 3;
 int winHeight = 3;
 int minDistance = 5;
 float threshold = 0;
 bool suppression = true;
 int method = 1;
 float radius = 10;

 for (int i = 0, ie = 50; i < ie; ++i)
 {
  PointCloudTXYZI* out = new PointCloudTXYZI;
  pcl::HarrisKeypoint2D<pcl::PointXYZI, pcl::PointXYZI> harris((pcl::HarrisKeypoint2D<pcl::PointXYZI, pcl::PointXYZI>::ResponseMethod)method, winWidth, winHeight, minDistance, threshold);
  harris.setRadiusSearch(radius);
  harris.setNumberOfThreads(1);
  harris.setInputCloud(cloud);
  harris.setNonMaxSupression(suppression);
  harris.setRefine(false);
  harris.compute(*out);
  printf("run: %i, in size: %lu, out size :%lu \n", i, cloud->size(), out->size());
  //delete out; //The result cloud is not deleted as this will increase the non-deterministic behaviour.
 }
}


`pcl::PointCloud<pcl::PointXYZ>` 是一个三维点云容器,用于存储PointXYZ类型的点(通常包含x, y, z坐标)。而 `pcl::PointCloud<pcl::PointXYZ>::Ptr` 是一个指向 `pcl::PointCloud<pcl::PointXYZ>` 类型对象的指针,它是一个动态内存分配的对象引用。 1. **实例化**: - 直接创建 `pcl::PointCloud<pcl::PointXYZ> cloud;` 是直接创建了一个 `pcl::PointCloud` 对象,它的生命周期与当前作用域内的变量关联。 ```cpp pcl::PointCloud<pcl::PointXYZ> cloud; ``` 2. **智能指针**: - `pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr(new pcl::PointCloud<pcl::PointXYZ>);` 则是通过 `new` 关键字动态分配内存并创建了一个 `pcl::PointCloud<pcl::PointXYZ>` 的副本,赋值给 `cloud_ptr` 指针。这样做的好处是可以手动管理内存,当不再需要时调用 `delete cloud_ptr;` 来释放内存。 ```cpp pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr(new pcl::PointCloud<pcl::PointXYZ>); ``` **区别和联系**: - `pcl::PointCloud<pcl::PointXYZ>` 是一个值类型对象,当你赋值给另一个变量时,实际上是复制整个对象。 - `pcl::PointCloud<pcl::PointXYZ>::Ptr` 是引用类型,它只是一个内存地址的引用,不会复制对象,但可以通过指针修改原始对象。 - `cloud_ptr` 拥有所有权,允许你在任何时候决定何时释放内存,而不需要担心忘记这样做。 - **联系**: - 如果你需要长期保持对某个 `pcl::PointCloud` 的引用,使用 `Ptr` 可以避免无意中丢失对象。 - `cloud_ptr` 可以方便地传递给函数,因为函数可以安全地修改通过指针传入的对象,而无需返回新对象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值