shared_ptr使用实例

文章目录

  • shared_ptr使用实例
  • unique_ptr使用实例
  • cv::fitLine中斜率为正无穷的情况,需要特殊考虑
 std::string path = "D:\\code\\test_base_opencv\\example\\depth_98.raw";std::string save_path = "D:\\code\\test_base_opencv\\example\\";int cv_image_type = CV_16UC1;int rectify_height_ = 768;int rectify_width_ = 480;cv::Mat input_image(rectify_height_, rectify_width_,CV_16UC1);ReadRawImage(input_image, path, rectify_width_, rectify_height_, CV_16UC1);cv::imwrite(save_path + "depth_888.png", input_image);auto fliped_img_depth = std::shared_ptr<uint8_t>(new uint8_t[rectify_width_ * rectify_height_ * 2](),[](uint8_t* p) { delete[] p; });if (fliped_img_depth.get() == nullptr) {std::cout << "DLOG_F  ERROR, fliped_img_depth alloc err" << std::endl;return 0;}cv::Mat image_fliped(rectify_height_, rectify_width_, CV_16UC1, fliped_img_depth.get());cv::flip(input_image, image_fliped, 1);cv::imwrite(save_path + "depth_image_fliped_888.png", image_fliped);getchar();return 0;

unique_ptr使用实例

std::unique_ptr<deptrum::Frame> DepthGenerate::MakeFrame(deptrum::FrameType frame_type,const deptrum::RawFrames& raw_frame,int cols,int rows,int bytes_per_pixel,void* data) {std::unique_ptr<deptrum::Frame> frame{ std::make_unique<deptrum::Frame>() };frame->index = raw_frame.idx;frame->size = cols * rows * bytes_per_pixel;frame->data = data;frame->timestamp = raw_frame.timestamp;frame->frame_type = frame_type;frame->temperature = raw_frame.ntc_value;frame->rows = rows;frame->cols = cols;frame->bytes_per_pixel = bytes_per_pixel;return frame;}

cv::fitLine中斜率为正无穷的情况,需要特殊考虑

 std::vector<cv::Point2f> point;Point2f point_temp;int length = 200;for (size_t i = 0; i < length; i++){point_temp.x = i;point_temp.y = 3 * i;point.emplace_back(point_temp);}cv::Vec4f line_para;cv::fitLine(point, line_para, cv::DIST_L2, 0, 1e-2, 1e-2);float k_line = line_para[1] / line_para[0];// zero pointint zero_line = line_para[2] - line_para[3] / k_line;// float intercept_line = line_para[3] - k_line * line_para[2];printf("k_line=%f,zero_line=%f\n", k_line, zero_line);

【Smart_Point】unique_ptr与shared_ptr使用实例相关推荐

  1. C++11中的智能指针unique_ptr、shared_ptr和weak_ptr详解

    目录 1.引言 2.什么是智能指针? 3.在Visual Studio中查看智能指针的源码实现 4.独占式指针unique_ptr 4.1.查看unique_ptr的源码实现片段 4.2.为什么uni ...

  2. c++11 智能指针 unique_ptr、shared_ptr与weak_ptr

    C++11中有unique_ptr.shared_ptr与weak_ptr等智能指针(smart pointer),定义在<memory>中. 可以对动态资源进行管理,保证任何情况下,已构 ...

  3. C++ 智能指针 :内存泄漏、 RAII、智能指针、auto_ptr、unique_ptr、shared_ptr、weak_ptr、定制删除器deleter

    文章目录 内存泄漏 什么是内存泄漏 内存泄漏的危害: 如何避免内存泄漏 RAII 智能指针 auto_ptr unique_ptr shared_ptr 循环引用问题 weak_ptr 定制删除器 内 ...

  4. C++11智能指针(unique_ptr、shared_ptr、weak_ptr)boost::scoped_ptr

    C++11智能指针(unique_ptr.shared_ptr.weak_ptr)_-码农小非-的专栏-CSDN博客_c++ shared_ptr weak_ptr 原创)智能指针拾遗 (原创)智能指 ...

  5. C++智能指针详解(auto_ptr、unique_ptr、shared_ptr)

    文章目录 1. 智能指针的应用场景 2. 智能指针的介绍 3. 智能指针的使用与原理 3.1 auto_ptr 3.2 unique_ptr 3.3 shared_ptr 3.4 shared_ptr ...

  6. C++智能指针unique_ptr与shared_ptr

    文章目录 1.unique_ptr特点 2.unique_ptr例子 3.unique_ptr总结 4.shared_ptr特点 5.shared_ptr例子 6.shared_ptr中的自定义删除器 ...

  7. 智能指针(unique_ptr、shared_ptr、weak_ptr)

    主要参考链接:C++ 智能指针最佳实践&源码分析 参考链接:C++11 make_shared - 简书 智能指针在 C++11 标准中被引入真正的标准库(C++98 中引入的 auto_pt ...

  8. C++智能指针shared_ptr使用实例

    被new/delete折磨过之后,才能真正体会智能指针有多好用. 智能指针是用于管理指针的类. 其中shared_ptr是专门管理那些可能被多个地方用到的指针的类. C++11中智能指针的头文件是: ...

  9. 智能指针shared_ptr、unique_ptr、weak_ptr

    智能指针 智能指针解决的问题 智能指针分类 shared_ptr 内存模型图 shared_ptr示例 shared_ptr含义 shared_ptr基本用法及常用函数 常用函数 智能指针的构造,初始 ...

最新文章

  1. 软件工程实践第二次作业——个人项目实战(数独)
  2. 三极管的发射极与集电极之间的关系
  3. Lintcode 993 解题思路和c++代码
  4. 今天又看到的Acm指南
  5. 在wine里安装了IE6
  6. javascript 自定义Map
  7. 从ARM裸机看驱动之按键中断方式控制LED(一)
  8. ZOJ - 4114 Flipping Game
  9. 设计一些自学软件的小测试demo吧。
  10. Linux终端快捷键的使用
  11. 京东返利PHP采集关键字,PHP实现京东API的授权HASH算法
  12. Vue中配置代理服务器
  13. 《惢客创业日记》2021.01.22(周五)英雄心,狗熊命?
  14. 计算机win10装机目的,win10装机版是什么意思
  15. PPT修行之路(二)-素材库
  16. JS获取ul中li的值同步到搜索框
  17. Coding life,云栖社区的个性化首页上线
  18. 动画对象(lv_anim_t)的应用
  19. JIRA常用的企业项目管理和开发软件
  20. 【Java8】函数式接口

热门文章

  1. android 美颜 技术点,《Android 美颜类相机开发汇总》第六章 Android OpenGLES 美妆定制实现...
  2. 获取oracle数据库war报告,Oracle 数据库开发及SQL基础实战
  3. java intent 传递集合对象_Intent之对象传递(Parcelable传递对象和对象集合)
  4. 【camera-lidar】自动驾驶相机-激光雷达融合方案综述
  5. POJ 2226 Muddy Fields 最小点覆盖+加建图(好题)
  6. 奇葩错误 WIFI搜不到、无线网卡连接不上
  7. TensorFlow(2)图(默认图与自定义图) TensorBoard可视化
  8. 【面向对象编程】(4) 类的继承,重构父类中的方法
  9. size_t和int区别
  10. 强哥PS强化培训班课程目录