当前位置: 首页 > news >正文

深圳网站建设 案例爱站工具查询

深圳网站建设 案例,爱站工具查询,淮安建设网站制作,1111wk域名更换由于项目中以一个环节需要使用kdtree ,对性能要求比较严苛&#xff0c;所以看看那个kdtree效率高一些。对比了opencv和pcl。 #include <array> #include <deque> #include <fstream> #include <opencv2/highgui.hpp> #include <opencv2/imgproc.hpp…

由于项目中以一个环节需要使用kdtree ,对性能要求比较严苛,所以看看那个kdtree效率高一些。对比了opencv和pcl。


#include <array>
#include <deque>
#include <fstream>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/flann.hpp>#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/kdtree/kdtree_flann.h>#include <iostream>
#include <iostream>
#include <cstdlib>  // 用于 rand()
#include <ctime>    // 用于 time()int main() {// 初始化随机种子std::srand(std::time(0));// 生成 5000 个随机的二维点int numPoints = 5000;std::vector<cv::Point2f> points;pcl::PointCloud<pcl::PointXY>::Ptr cloud(new pcl::PointCloud<pcl::PointXY>);// 随机生成点,范围为 (-100, 100)for (int i = 0; i < numPoints; ++i) {float x = static_cast<float>(rand() % 200 - 100);  // x 坐标在 [-100, 100] 范围内float y = static_cast<float>(rand() % 200 - 100);  // y 坐标在 [-100, 100] 范围内points.push_back(cv::Point2f(x, y));cloud->points.push_back(pcl::PointXY(x, y));}// 2. 将点转换为 cv::Mat 格式cv::Mat pointMat(points.size(), 2, CV_32F);  // 每个点是 2D(x, y)for (size_t i = 0; i < points.size(); i++) {pointMat.at<float>(i, 0) = points[i].x; pointMat.at<float>(i, 1) = points[i].y;}// 3. 创建 KD-Tree 索引(使用 FLANN)cv::flann::Index kdtree(pointMat, cv::flann::KDTreeIndexParams(4)); // 4 表示树的分支数// 获取程序开始时的时钟时间std::clock_t start = std::clock();for(int i = 0 ;i < 200; ++i){std::vector<int> indices(1);     // 最近邻的索引std::vector<float> dists(1);     // 最近邻的距离float x = static_cast<float>(rand() % 200 - 100);  // x 坐标在 [-100, 100] 范围内float y = static_cast<float>(rand() % 200 - 100);  // y 坐标在 [-100, 100] 范围内cv::Mat query = (cv::Mat_<float>(1, 2) << x, y);kdtree.knnSearch(query, indices, dists, 1, cv::flann::SearchParams(32));// std::cout << "Query point: " << query << std::endl;// std::cout << "Closest point: " << pointMat.row(indices[0]) << std::endl;// std::cout << "Distance: " << dists[0] << std::endl;// std::cout << "----------------"  << std::endl;}std::clock_t end = std::clock();// 计算并输出经过的时间,单位是秒double duration = double(end - start) / CLOCKS_PER_SEC;std::cout << "opencv kdtree 搜索时间: " << duration << " 秒" << std::endl;/pcl::KdTreeFLANN<pcl::PointXY> pcl_kdtree;pcl_kdtree.setInputCloud(cloud);start = std::clock();for(int i = 0 ;i < 200; ++i){std::vector<int> indices(1);     // 最近邻的索引std::vector<float> dists(1);     // 最近邻的距离float x = static_cast<float>(rand() % 200 - 100);  // x 坐标在 [-100, 100] 范围内float y = static_cast<float>(rand() % 200 - 100);  // y 坐标在 [-100, 100] 范围内pcl::PointXY searchPoint;searchPoint.x = x;searchPoint.y = y;pcl_kdtree.nearestKSearch(searchPoint,1, indices, dists);// std::cout << "Query point: " << query << std::endl;// std::cout << "Closest point: " << pointMat.row(indices[0]) << std::endl;// std::cout << "Distance: " << dists[0] << std::endl;// std::cout << "----------------"  << std::endl;}end = std::clock();// 计算并输出经过的时间,单位是秒duration = double(end - start) / CLOCKS_PER_SEC;std::cout << "pcl kdtree 搜索时间: " << duration << " 秒" << std::endl;return 0;
}

CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)# 设置项目名称
project(test_kdtree)# 查找 OpenCV 包
find_package(OpenCV REQUIRED)
find_package(PCL REQUIRED)# 显示 OpenCV 的版本和路径
message(STATUS "OpenCV version: ${OpenCV_VERSION}")
message(STATUS "OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV_LIBS: ${OpenCV_LIBS}")# 设置源文件
set(SOURCE_FILES test_kdtree.cpp)# 添加可执行文件
add_executable(${PROJECT_NAME} ${SOURCE_FILES})# 链接 OpenCV 库到目标程序
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}  ${PCL_LIBRARIES})# 包含 OpenCV 的头文件路径
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS})

结果:

http://www.hrbkazy.com/news/35666.html

相关文章:

  • 泉州(晋江)网站建设百度搜索指数的数据来源
  • 网站栏目页优化广州seo好找工作吗
  • wordpress 源码交付怎样优化网络
  • 会员管理网站模板谷歌浏览器app
  • wordpress数据库域名seo整站优化技术培训
  • 无为做网站云速seo百度点击
  • wordpress 找站点 百度一下
  • 郑州同济医院口碑怎样seo外链增加
  • 坦克大战网站开发课程设计报告市场调研怎么做
  • wordpress插件安装不seo诊断分析在线工具
  • 温州网站制作哪家好西安网站建设排名
  • 手机建站官网沈阳网站制作公司
  • 建设部网站官网证书编号外贸网站外链平台
  • 删除网站留言板功能互动网站建设
  • 自己的公司怎么做网站小红书推广方式
  • 建设银行网站登录首页百度推广代理公司哪家好
  • 游戏网站设计书百度竞价推广代理
  • 新浪博客怎么给自己网站做链接怎么制作公司网页
  • 网站设计与规划论文seo公司多少钱
  • 网站制作 网络推广营销活动
  • 免费政府网站2022年最新热点素材
  • 丰台手机网站设计公司设计网站
  • 网站建设的工作全球搜索引擎网站
  • 泉做网站的公司百度公司图片
  • 点创网站建设长春模板建站代理
  • 网站色彩运用网络推广公司联系方式
  • 北京网站建设公司内江知乎seo排名的搜软件
  • 宁波谷歌seo推广公司网站seo设置是什么
  • 石家庄网推公司河北seo基础知识
  • 网站建设阶段b2b平台是什么意思