-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathpose_renderer.cpp
78 lines (67 loc) · 2.33 KB
/
pose_renderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "pose_renderer.h"
PoseRenderer::PoseRenderer(std::string model_path, cv::Mat depth, cv::Mat K):
#ifdef CUDA_ON
tris(model.tris.size()),
#else
tris(model.tris),
#endif
model(model_path) // model inits first
{
#ifdef CUDA_ON
thrust::copy(model.tris.begin(), model.tris.end(), tris.begin_thr());
#endif
}
void PoseRenderer::set_K_width_height(cv::Mat K, int width, int height)
{
assert(K.type() == CV_32F);
this->K = K;
this->width = width;
this->height = height;
proj_mat = cuda_renderer::compute_proj(K, width, height);
}
template<typename F>
auto PoseRenderer::render_what(F f, std::vector<cv::Mat> &init_poses, float down_sample)
{
const int width_local = width/down_sample;
const int height_local = height/down_sample;
std::vector<cuda_renderer::Model::mat4x4> mat4_v(init_poses.size());
for(size_t i=0; i<init_poses.size();i++) mat4_v[i].init_from_cv(init_poses[i]);
auto depths = cuda_renderer::render(tris, mat4_v, width_local, height_local, proj_mat);
return f(depths, width_local, height_local, init_poses.size());
}
std::vector<cv::Mat> PoseRenderer::render_depth(std::vector<cv::Mat> &init_poses, float down_sample)
{
#ifdef CUDA_ON
return render_what(cuda_renderer::raw2depth_uint16_cuda, init_poses, down_sample);
#else
return render_what(cuda_renderer::raw2depth_uint16_cpu, init_poses, down_sample);
#endif
}
std::vector<cv::Mat> PoseRenderer::render_mask(std::vector<cv::Mat> &init_poses, float down_sample)
{
#ifdef CUDA_ON
return render_what(cuda_renderer::raw2mask_uint8_cuda, init_poses, down_sample);
#else
return render_what(cuda_renderer::raw2mask_uint8_cpu, init_poses, down_sample);
#endif
}
std::vector<std::vector<cv::Mat> > PoseRenderer::render_depth_mask(std::vector<cv::Mat> &init_poses, float down_sample)
{
#ifdef CUDA_ON
return render_what(cuda_renderer::raw2depth_mask_cuda, init_poses, down_sample);
#else
return render_what(cuda_renderer::raw2depth_mask_cpu, init_poses, down_sample);
#endif
}
cv::Mat PoseRenderer::view_dep(cv::Mat dep)
{
cv::Mat map = dep;
double min;
double max;
cv::minMaxIdx(map, &min, &max);
cv::Mat adjMap;
map.convertTo(adjMap,CV_8UC1, 255 / (max-min), -min);
cv::Mat falseColorsMap;
applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_HOT);
return falseColorsMap;
}