编程常用代码

2022-07-12 05:15:11   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《编程常用代码》,欢迎阅读!
常用,编程,代码
编程常用代码

#includechrono::steady_clock::time_point t1=chrono::steady_clock::now();//do somethingchrono::steady_clock::time_point t2=chrono::steady_clock::now();chrono::duration time_used=chrono::duration_cast>(t2-t1); double time0=static_cast(getTickCount());//do somethingtime0=((double)getTickCount()-time0)/getTickFrequency(); clock_t start = clock();//do somethingclock_t finish = clock();double totaltime = (double)(finish - start) / CLOCKS_PER_SEC;睡眠:ros::Duration(0.).sleep(); // sleep for half a second #include sleepn//nDUtils::Random::RandomInt(0,n);//0~n std::random_device rd;int x = rd() % 100; int x = std::rand() % 100;float b = 255 * float(rand()) / RAND_MAX; RNG rng;//产生64位整数int N1 = rng;//产生[0,1)范围内均匀分布的double型数据。double N1d = rng.uniform(0.,1.); //产生符合均值为1,标准差为0.5的高斯分布的随double N1g = 1 + rng.gaussian(0.5); cv::RNG rng;double w_sigma=1.0;rng.gaussian(w_sigma)常量M_PI (math.h)CV_PI (opencv)DBL_MAX (float.h(内置宏定义,double最大值)进度条printf(“\r bar: %m.nf %% \r”, value * 100);fflush(stdout);类的智能指针#include // 定义class Image {public: using Ptr = std::shared_ptr; // 使用别名}// 使用Image::Ptr image_pointer = Image::Ptr(new Image());Image image;Image::Ptr image_pointer = std::make_shared(image);使#include pcl::PointCloud::Ptr point_cloud_xyzrgb_ = boost::make_shared>(); 注:typedef boost::shared_ptr > Ptr;不然会报错:Assertion `px != 0' failed编程习惯://用宏定义(不要写死)#define IMG_WIDTH 640#define IMG_HIGHT 480 //宏定义换行用'\' //调试宏#define DEBUG#ifdef DEBUG//do something#endif //注释代码块#if 0//do something#endif //函数入口进行参数检查assert(条件/表达式); 遵循doxygen注释规范 小数后面加f2.1double,8字节)2.1fflaot,4 float*2


>>n for循环并行处理:包含OpenMP的头文件:#includefor循环前面加上一行:#pragma omp parallel for————————————————


本文来源:https://www.wddqxz.cn/cad876f054270722192e453610661ed9ac515595.html

相关推荐