Open3D Image 转 OpenCV Mat
cv::Mat o3d_cv(const geometry::Image& A) {
int type = A.num_of_channels_ == 1 ? CV_16UC1 : CV_8UC3;//depth, otherwise color
return cv::Mat(A.height_, A.width_, type, (void*)A.data_.data());
}
OpenCV Mat 转 Open3D Image
geometry::Image o3d_cv(const cv::Mat& A) {
geometry::Image B;
int bytes_per_channel = (A.depth() / 2 + 1);//refer to the fuction depth
B.Prepare(A.cols, A.rows, A.channels(), bytes_per_channel);
std::memcpy(B.data_.data(), A.data, A.total() * A.channels() * bytes_per_channel);
return B;
}
对Open3D RGBD影像下采样四倍
std::shared_ptr<geometry::RGBDImage> rgbd=geometry::RGBDImage::CreateFromColorAndDepth(color, depth, 1, 3000.0, false);
for (int j = 0; j < 2; j++) {
cv::Mat color = o3d_cv(rgbd->color_);
cv::resize(color, color, cv::Size(color.cols / 2, color.rows / 2));
rgbd = make_shared<geometry::RGBDImage>(o3d_cv(color), *rgbd->depth_.Downsample());
if (j == 0)continue;
cv::imshow("color image", color);
cv::waitKey(1);
}