【Smart_Point】unique_ptr与shared_ptr使用实例
生活随笔
收集整理的這篇文章主要介紹了
【Smart_Point】unique_ptr与shared_ptr使用实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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使用实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 先奇家用投影仪可以换灯泡吗?
- 下一篇: 爱情累不累是什么歌啊?