日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

【Smart_Point】unique_ptr与shared_ptr使用实例

發(fā)布時(shí)間:2023/11/27 生活经验 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Smart_Point】unique_ptr与shared_ptr使用实例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

shared_ptr使用實(shí)例

文章目錄

    • shared_ptr使用實(shí)例
    • unique_ptr使用實(shí)例
    • 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使用實(shí)例

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);

總結(jié)

以上是生活随笔為你收集整理的【Smart_Point】unique_ptr与shared_ptr使用实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。