Skip to content
Snippets Groups Projects
Commit 43f32841 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

WIP Depth camera normals calc

parent 7aa42052
No related branches found
No related tags found
1 merge request!71Implements #130 for optional MLS merging
......@@ -36,66 +36,16 @@ struct DepthCamera {
// Host part //
///////////////
__host__
DepthCamera() {
/*d_depthData = NULL;
d_colorData = NULL;
d_depthArray = NULL;
d_colorArray = NULL;*/
depth_mat_ = nullptr;
colour_mat_ = nullptr;
point_mat_ = nullptr;
normal_mat_ = nullptr;
depth_tex_ = nullptr;
colour_tex_ = nullptr;
normal_tex_ = nullptr;
}
__host__
void alloc(const DepthCameraParams& params, bool withNormals=false) { //! todo resizing???
depth_mat_ = new cv::cuda::GpuMat(params.m_imageHeight, params.m_imageWidth, CV_32FC1);
colour_mat_ = new cv::cuda::GpuMat(params.m_imageHeight, params.m_imageWidth, CV_8UC4);
depth_tex_ = new ftl::cuda::TextureObject<float>((cv::cuda::PtrStepSz<float>)*depth_mat_);
colour_tex_ = new ftl::cuda::TextureObject<uchar4>((cv::cuda::PtrStepSz<uchar4>)*colour_mat_);
data.depth = depth_tex_->cudaTexture();
data.colour = colour_tex_->cudaTexture();
data.params = params;
if (withNormals) {
point_mat_ = new cv::cuda::GpuMat(params.m_imageHeight, params.m_imageWidth, CV_32FC3);
normal_mat_ = new cv::cuda::GpuMat(params.m_imageHeight, params.m_imageWidth, CV_32FC4);
normal_tex_ = new ftl::cuda::TextureObject<float4>((cv::cuda::PtrStepSz<float4>)*normal_mat_);
data.normal = normal_tex_->cudaTexture();
} else {
data.normal = 0;
}
}
//__host__
//void updateParams(const DepthCameraParams& params) {
// updateConstantDepthCameraParams(params);
//}
__host__
void updateData(const cv::Mat &depth, const cv::Mat &rgb, cv::cuda::Stream &stream) {
depth_mat_->upload(depth, stream);
colour_mat_->upload(rgb, stream);
}
__host__
void free() {
if (depth_mat_) delete depth_mat_;
if (colour_mat_) delete colour_mat_;
if (point_mat_) delete point_mat_;
if (normal_mat_) delete normal_mat_;
delete depth_tex_;
delete colour_tex_;
if (normal_tex_) delete normal_tex_;
}
// TODO(Nick) Should not need to pass all these pointers to device
__host__ DepthCamera();
__host__ void alloc(const DepthCameraParams& params, bool withNormals=false);
__host__ void updateData(const cv::Mat &depth, const cv::Mat &rgb, cv::cuda::Stream &stream);
__host__ void free();
__host__ void _computeNormals(cudaStream_t stream);
cv::cuda::GpuMat *depth_mat_;
cv::cuda::GpuMat *colour_mat_;
cv::cuda::GpuMat *point_mat_;
......@@ -103,9 +53,8 @@ struct DepthCamera {
ftl::cuda::TextureObject<float> *depth_tex_;
ftl::cuda::TextureObject<uchar4> *colour_tex_;
ftl::cuda::TextureObject<float4> *normal_tex_;
//cudaTextureObject_t depth_obj_;
//cudaTextureObject_t colour_obj_;
// This part is sent to device
DepthCameraCUDA data;
};
}
......
#include <ftl/depth_camera.hpp>
using ftl::voxhash::DepthCamera;
extern "C" void computeNormals(float4* d_output, float3* d_input, unsigned int width, unsigned int height);
extern "C" void convertDepthFloatToCameraSpaceFloat3(float3* d_output, float* d_input, float4x4 intrinsicsInv, unsigned int width, unsigned int height, const DepthCameraData& depthCameraData);
DepthCamera::DepthCamera() {
depth_mat_ = nullptr;
colour_mat_ = nullptr;
point_mat_ = nullptr;
normal_mat_ = nullptr;
depth_tex_ = nullptr;
colour_tex_ = nullptr;
normal_tex_ = nullptr;
}
void DepthCamera::alloc(const DepthCameraParams& params, bool withNormals=false) { //! todo resizing???
depth_mat_ = new cv::cuda::GpuMat(params.m_imageHeight, params.m_imageWidth, CV_32FC1);
colour_mat_ = new cv::cuda::GpuMat(params.m_imageHeight, params.m_imageWidth, CV_8UC4);
depth_tex_ = new ftl::cuda::TextureObject<float>((cv::cuda::PtrStepSz<float>)*depth_mat_);
colour_tex_ = new ftl::cuda::TextureObject<uchar4>((cv::cuda::PtrStepSz<uchar4>)*colour_mat_);
data.depth = depth_tex_->cudaTexture();
data.colour = colour_tex_->cudaTexture();
data.params = params;
if (withNormals) {
point_mat_ = new cv::cuda::GpuMat(params.m_imageHeight, params.m_imageWidth, CV_32FC3);
normal_mat_ = new cv::cuda::GpuMat(params.m_imageHeight, params.m_imageWidth, CV_32FC4);
normal_tex_ = new ftl::cuda::TextureObject<float4>((cv::cuda::PtrStepSz<float4>)*normal_mat_);
data.normal = normal_tex_->cudaTexture();
} else {
data.normal = 0;
}
}
void DepthCamera::free() {
if (depth_mat_) delete depth_mat_;
if (colour_mat_) delete colour_mat_;
if (point_mat_) delete point_mat_;
if (normal_mat_) delete normal_mat_;
delete depth_tex_;
delete colour_tex_;
if (normal_tex_) delete normal_tex_;
}
void DepthCamera::updateData(const cv::Mat &depth, const cv::Mat &rgb, cv::cuda::Stream &stream) {
depth_mat_->upload(depth, stream);
colour_mat_->upload(rgb, stream);
if (normal_mat_) {
_computeNormals(cv::cuda::StreamAccessor::getStream(stream));
}
}
void DepthCamera::_computeNormals(cudaStream_t stream) {
convertDepthFloatToCameraSpaceFloat3(m_data.d_depth3, m_data.d_depth, m_params.m_intrinsicsInverse, m_params.m_width, m_params.m_height, cameraData);
computeNormals(m_data.d_normals, m_data.d_depth3, m_params.m_width, m_params.m_height);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment