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