【Smart_Point】unique_ptr与shared_ptr使用实例

shared_ptr使用实例

	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 point
	int 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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大江东去浪淘尽千古风流人物

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值