Skip to content

Commit d0a48c8

Browse files
author
swayfreeda
committed
fix problems of texturing
1 parent 3170c83 commit d0a48c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1497
-1553
lines changed

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ add_subdirectory(mvs)
1919
add_subdirectory(examples)
2020
add_subdirectory(surface)
2121
add_subdirectory(texturing)
22-
add_subdirectory(3rdParty/rayint)
22+
add_subdirectory(3rdParty/mrf)
23+
add_subdirectory(3rdParty/coldet)
24+
add_subdirectory(3rdParty/gco)
25+
#add_subdirectory(3rdParty/rayint)
2326
#add_subdirectory(3rdParty/eigen)
2427
#add_subdirectory(3rdParty/mapmap)

core/depthmap.cc

100644100755
+45-71
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ CORE_NAMESPACE_END
135135
CORE_NAMESPACE_BEGIN
136136
CORE_GEOM_NAMESPACE_BEGIN
137137

138-
// todo foot print 是什么意思??
139138
float
140139
pixel_footprint (std::size_t x, std::size_t y, float depth,
141140
math::Matrix3f const& invproj)
@@ -168,11 +167,13 @@ dm_make_triangle (TriangleMesh* mesh, core::Image<unsigned int>& vidx,
168167
core::TriangleMesh::VertexList& verts(mesh->get_vertices());
169168
core::TriangleMesh::FaceList& faces(mesh->get_faces());
170169

171-
for (int j = 0; j < 3; ++j) {
170+
for (int j = 0; j < 3; ++j)
171+
{
172172
int iidx = i + (tverts[j] % 2) + width * (tverts[j] / 2);
173173
int x = iidx % width;
174174
int y = iidx / width;
175-
if (vidx.at(iidx) == MATH_MAX_UINT) {
175+
if (vidx.at(iidx) == MATH_MAX_UINT)
176+
{
176177
/* Add vertex for depth pixel. */
177178
vidx.at(iidx) = verts.size();
178179
float depth = dm->at(iidx, 0);
@@ -210,79 +211,59 @@ TriangleMesh::Ptr
210211
depthmap_triangulate (FloatImage::ConstPtr dm, math::Matrix3f const& invproj,
211212
float dd_factor, core::Image<unsigned int>* vids)
212213
{
213-
// 深度图不为空
214214
if (dm == nullptr)
215215
throw std::invalid_argument("Null depthmap given");
216216

217-
// 图像的宽和高
218217
int const width = dm->width();
219218
int const height = dm->height();
220219

221-
// 创建三角网格接结构体
222220
/* Prepare triangle mesh. */
223221
TriangleMesh::Ptr mesh(TriangleMesh::create());
224222

225223
/* Generate image that maps image pixels to vertex IDs. */
226-
// 创建映射图,将图像像素映射到三维点的索引
227224
core::Image<unsigned int> vidx(width, height, 1);
228225
vidx.fill(MATH_MAX_UINT);
229226

230-
// 在深度图中遍历2x2 blocks,并且创建三角面片
231227
/* Iterate over 2x2-blocks in the depthmap and create triangles. */
232228
int i = 0;
233-
for (int y = 0; y < height - 1; ++y, ++i) {
234-
for (int x = 0; x < width - 1; ++x, ++i) {
235-
229+
for (int y = 0; y < height - 1; ++y, ++i)
230+
{
231+
for (int x = 0; x < width - 1; ++x, ++i)
232+
{
236233
/* Cache the four depth values. */
237-
/*
238-
* 0, 1
239-
* 2, 3
240-
*/
241-
float depths[4] = { dm->at(i, 0), dm->at(i + 1, 0),
242-
dm->at(i + width, 0), dm->at(i + width + 1, 0)
243-
};
234+
float depths[4] = { dm->at(i, 0), dm->at(i + 1, 0),
235+
dm->at(i + width, 0), dm->at(i + width + 1, 0) };
244236

245237
/* Create a mask representation of the available depth values. */
246-
/* 创建mask记录深度有效的像素个数
247-
* mask=0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001,
248-
* 1010, 1011, 1100, 1101, 1110, 1111
249-
*/
250238
int mask = 0;
251239
int pixels = 0;
252-
for (int j = 0; j < 4; ++j){
253-
if (depths[j] > 0.0f) {
240+
for (int j = 0; j < 4; ++j)
241+
if (depths[j] > 0.0f)
242+
{
254243
mask |= 1 << j;
255244
pixels += 1;
256245
}
257-
}
258246

259-
// 至少保证3个深度值是可靠的
260247
/* At least three valid depth values are required. */
261248
if (pixels < 3)
262249
continue;
263250

264-
265251
/* Possible triangles, vertex indices relative to 2x2 block. */
266-
/* 可能出现的三角面片对,4个点有2个面片
267-
*/
268252
int tris[4][3] = {
269253
{ 0, 2, 1 }, { 0, 3, 1 }, { 0, 2, 3 }, { 1, 2, 3 }
270254
};
271255

272256
/* Decide which triangles to issue. */
273-
/* 决定用哪对面片
274-
*/
275257
int tri[2] = { 0, 0 };
276258

277-
switch (mask) {
278-
279-
case 7: tri[0] = 1; break; // 0111- 0,1,2
280-
case 11: tri[0] = 2; break; // 1011- 0,1,3
281-
case 13: tri[0] = 3; break; // 1101- 0,2,3
282-
case 14: tri[0] = 4; break; // 1110- 1,2,3
283-
case 15: // 1111- 0,1,2,3
259+
switch (mask)
260+
{
261+
case 7: tri[0] = 1; break;
262+
case 11: tri[0] = 2; break;
263+
case 13: tri[0] = 3; break;
264+
case 14: tri[0] = 4; break;
265+
case 15:
284266
{
285-
// 空圆特性
286267
/* Choose the triangulation with smaller diagonal. */
287268
float ddiff1 = std::abs(depths[0] - depths[3]);
288269
float ddiff2 = std::abs(depths[1] - depths[2]);
@@ -296,18 +277,21 @@ depthmap_triangulate (FloatImage::ConstPtr dm, math::Matrix3f const& invproj,
296277
}
297278

298279
/* Omit depth discontinuity detection if dd_factor is zero. */
299-
if (dd_factor > 0.0f) {
280+
if (dd_factor > 0.0f)
281+
{
300282
/* Cache pixel footprints. */
301283
float widths[4];
302-
for (int j = 0; j < 4; ++j) {
284+
for (int j = 0; j < 4; ++j)
285+
{
303286
if (depths[j] == 0.0f)
304287
continue;
305-
widths[j] = pixel_footprint(x + (j % 2), y + (j / 2), depths[j], invproj);// w, h, focal_len);
288+
widths[j] = pixel_footprint(x + (j % 2), y + (j / 2),
289+
depths[j], invproj);// w, h, focal_len);
306290
}
307291

308-
// 检查深度不一致性,相邻像素的深度差值不要超过像素宽度(三维空间中)的dd_factor倍
309292
/* Check for depth discontinuities. */
310-
for (int j = 0; j < 2 && tri[j] != 0; ++j) {
293+
for (int j = 0; j < 2 && tri[j] != 0; ++j)
294+
{
311295
int* tv = tris[tri[j] - 1];
312296
#define DM_DD_ARGS widths, depths, dd_factor
313297
if (dm_is_depthdisc(DM_DD_ARGS, tv[0], tv[1])) tri[j] = 0;
@@ -317,7 +301,8 @@ depthmap_triangulate (FloatImage::ConstPtr dm, math::Matrix3f const& invproj,
317301
}
318302

319303
/* Build triangles. */
320-
for (int j = 0; j < 2; ++j) {
304+
for (int j = 0; j < 2; ++j)
305+
{
321306
if (tri[j] == 0) continue;
322307
#define DM_MAKE_TRI_ARGS mesh.get(), vidx, dm.get(), invproj, i
323308
dm_make_triangle(DM_MAKE_TRI_ARGS, tris[tri[j] - 1]);
@@ -337,48 +322,42 @@ TriangleMesh::Ptr
337322
depthmap_triangulate (FloatImage::ConstPtr dm, ByteImage::ConstPtr ci,
338323
math::Matrix3f const& invproj, float dd_factor)
339324
{
340-
// 深度图像不为空
341325
if (dm == nullptr)
342326
throw std::invalid_argument("Null depthmap given");
343327

344-
// 图像的宽和高
345328
int const width = dm->width();
346329
int const height = dm->height();
347330

348-
// 彩色图像不为空,且和深度图像宽和高一致
349331
if (ci != nullptr && (ci->width() != width || ci->height() != height))
350332
throw std::invalid_argument("Color image dimension mismatch");
351333

352334
/* Triangulate depth map. */
353-
// 对深度图进行三角化
354335
core::Image<unsigned int> vids;
355336
core::TriangleMesh::Ptr mesh;
356337
mesh = core::geom::depthmap_triangulate(dm, invproj, dd_factor, &vids);
357338

358-
// 获取颜色
359339
if (ci == nullptr)
360340
return mesh;
361341

362-
/*计算顶点的颜色*/
363342
/* Use vertex index mapping to color the mesh. */
364343
core::TriangleMesh::ColorList& colors(mesh->get_vertex_colors());
365344
core::TriangleMesh::VertexList const& verts(mesh->get_vertices());
366345
colors.resize(verts.size());
367346

368-
// 像素个数
369347
int num_pixel = vids.get_pixel_amount();
370348
for (int i = 0; i < num_pixel; ++i)
371349
{
372-
// 像素没有对应的顶点
373350
if (vids[i] == MATH_MAX_UINT)
374351
continue;
375352

376353
math::Vec4f color(ci->at(i, 0), 0.0f, 0.0f, 255.0f);
377-
if (ci->channels() >= 3) {
354+
if (ci->channels() >= 3)
355+
{
378356
color[1] = ci->at(i, 1);
379357
color[2] = ci->at(i, 2);
380358
}
381-
else {
359+
else
360+
{
382361
color[1] = color[2] = color[0];
383362
}
384363
colors[vids[i]] = color / 255.0f;
@@ -393,29 +372,22 @@ TriangleMesh::Ptr
393372
depthmap_triangulate (FloatImage::ConstPtr dm, ByteImage::ConstPtr ci,
394373
CameraInfo const& cam, float dd_factor)
395374
{
396-
// 确保深度图不为空
397375
if (dm == nullptr)
398376
throw std::invalid_argument("Null depthmap given");
399-
400-
// 确保相机参数已经恢复
401377
if (cam.flen == 0.0f)
402378
throw std::invalid_argument("Invalid camera given");
403379

404380
/* Triangulate depth map. */
405-
// 计算投影矩阵的逆矩阵
406381
math::Matrix3f invproj;
407382
cam.fill_inverse_calibration(*invproj, dm->width(), dm->height());
408-
409-
// 对深度图进行三角化,注意此时的mesh顶点坐标位于相机坐标系中
410383
core::TriangleMesh::Ptr mesh;
411384
mesh = core::geom::depthmap_triangulate(dm, ci, invproj, dd_factor);
412385

413386
/* Transform mesh to world coordinates. */
414-
// 将网格从相机坐标系转化到世界坐标系中
415387
math::Matrix4f ctw;
416388
cam.fill_cam_to_world(*ctw);
417389
core::geom::mesh_transform(mesh, ctw);
418-
//mesh->recalc_normals(false, true); // Remove this?
390+
mesh->recalc_normals(false, true); // Remove this?
419391

420392
return mesh;
421393
}
@@ -534,10 +506,12 @@ depthmap_mesh_confidences (TriangleMesh::Ptr mesh, int iterations)
534506

535507
/* Find boundary vertices and remember them. */
536508
std::vector<std::size_t> vidx;
537-
MeshInfo mesh_info(mesh);
509+
VertexInfoList vinfo(mesh);
538510

539-
for (std::size_t i = 0; i < mesh_info.size(); ++i) {
540-
if (mesh_info[i].vclass == MeshInfo::VERTEX_CLASS_BORDER)
511+
for (std::size_t i = 0; i < vinfo.size(); ++i)
512+
{
513+
MeshVertexInfo const& info(vinfo[i]);
514+
if (info.vclass == VERTEX_CLASS_BORDER)
541515
vidx.push_back(i);
542516
}
543517

@@ -557,7 +531,7 @@ depthmap_mesh_confidences (TriangleMesh::Ptr mesh, int iterations)
557531
std::swap(vidx, cvidx);
558532
for (std::size_t i = 0; i < cvidx.size(); ++i)
559533
{
560-
MeshInfo::VertexInfo info = mesh_info[cvidx[i]];
534+
MeshVertexInfo info = vinfo[cvidx[i]];
561535
for (std::size_t j = 0; j < info.verts.size(); ++j)
562536
if (confs[info.verts[j]] == 1.0f)
563537
vidx.push_back(info.verts[j]);
@@ -586,11 +560,11 @@ depthmap_mesh_peeling (TriangleMesh::Ptr mesh, int iterations)
586560
/* Iteratively invalidate triangles at the boundary. */
587561
for (int iter = 0; iter < iterations; ++iter)
588562
{
589-
MeshInfo mesh_info(mesh);
590-
for (std::size_t i = 0; i < mesh_info.size(); ++i)
563+
VertexInfoList::Ptr vinfo(VertexInfoList::create(mesh));
564+
for (std::size_t i = 0; i < vinfo->size(); ++i)
591565
{
592-
MeshInfo::VertexInfo const& info(mesh_info[i]);
593-
if (info.vclass == MeshInfo::VERTEX_CLASS_BORDER)
566+
MeshVertexInfo const& info(vinfo->at(i));
567+
if (info.vclass == VERTEX_CLASS_BORDER)
594568
for (std::size_t j = 0; j < info.faces.size(); ++j)
595569
for (int k = 0; k < 3; ++k)
596570
{

core/depthmap.h

100644100755
+15-31
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#ifndef MVE_DEPTHMAP_HEADER
1111
#define MVE_DEPTHMAP_HEADER
1212

13-
#include "core/defines.h"
1413
#include "math/vector.h"
1514
#include "math/matrix.h"
15+
#include "core/defines.h"
1616
#include "core/camera.h"
1717
#include "core/image.h"
1818
#include "core/mesh.h"
@@ -61,7 +61,7 @@ depthmap_bilateral_filter (FloatImage::ConstPtr dm,
6161
template <typename T>
6262
void
6363
depthmap_convert_conventions (typename Image<T>::Ptr dm,
64-
math::Matrix3f const& invproj, bool to_mve);
64+
math::Matrix3f const& invproj, bool to_core);
6565

6666
CORE_IMAGE_NAMESPACE_END
6767
CORE_NAMESPACE_END
@@ -89,7 +89,7 @@ pixel_3dpos (std::size_t x, std::size_t y, float depth,
8989
math::Matrix3f const& invproj);
9090

9191
/**
92-
* \description * Algorithm to triangulate depth maps.
92+
* Algorithm to triangulate depth maps.
9393
*
9494
* A factor may be specified that guides depth discontinuity detection. A
9595
* depth discontinuity between pixels is assumed if depth difference is
@@ -100,41 +100,25 @@ pixel_3dpos (std::size_t x, std::size_t y, float depth,
100100
* If 'vids' is not null, image content is replaced with vertex indices for
101101
* each pixel that generated the vertex. Index MATH_MAX_UINT corresponds to
102102
* a pixel that did not generate a vertex.
103-
* @param dm -- 深度图
104-
* @param invproj -- 投影矩阵的逆矩阵
105-
* @param dd_factor -- 不确定因子
106-
* @param vids --可视图像
107-
* @return
108103
*/
109104
TriangleMesh::Ptr
110105
depthmap_triangulate (FloatImage::ConstPtr dm, math::Matrix3f const& invproj,
111106
float dd_factor = 5.0f, core::Image<unsigned int>* vids = nullptr);
112107

113-
114-
/**
115-
* \description A helper function that triangulates the given depth map with optional
116-
* color image (which generates additional per-vertex colors) in local
117-
* image coordinates.
118-
* @param dm
119-
* @param ci
120-
* @param invproj
121-
* @param dd_factor
122-
* @return
123-
*/
108+
/**
109+
* A helper function that triangulates the given depth map with optional
110+
* color image (which generates additional per-vertex colors) in local
111+
* image coordinates.
112+
*/
124113
TriangleMesh::Ptr
125114
depthmap_triangulate (FloatImage::ConstPtr dm, ByteImage::ConstPtr ci,
126115
math::Matrix3f const& invproj, float dd_factor = 5.0f);
127116

128-
/**
129-
* \description A helper function that triangulates the given depth map with optional
130-
* color image (which generates additional per-vertex colors) and transforms
131-
* the mesh into the global coordinate system.
132-
* @param dm -- 深度图像
133-
* @param ci -- 彩色图像
134-
* @param cam -- 相机参数
135-
* @param dd_factor -- ??
136-
* @return
137-
*/
117+
/**
118+
* A helper function that triangulates the given depth map with optional
119+
* color image (which generates additional per-vertex colors) and transforms
120+
* the mesh into the global coordinate system.
121+
*/
138122
TriangleMesh::Ptr
139123
depthmap_triangulate (FloatImage::ConstPtr dm, ByteImage::ConstPtr ci,
140124
CameraInfo const& cam, float dd_factor = 5.0f);
@@ -176,7 +160,7 @@ CORE_IMAGE_NAMESPACE_BEGIN
176160
template <typename T>
177161
inline void
178162
depthmap_convert_conventions (typename Image<T>::Ptr dm,
179-
math::Matrix3f const& invproj, bool to_mve)
163+
math::Matrix3f const& invproj, bool to_core)
180164
{
181165
std::size_t w = dm->width();
182166
std::size_t h = dm->height();
@@ -190,7 +174,7 @@ depthmap_convert_conventions (typename Image<T>::Ptr dm,
190174
// Measure length of viewing ray
191175
double len = px.norm();
192176
// Either divide or multiply with the length
193-
dm->at(pos) *= (to_mve ? len : 1.0 / len);
177+
dm->at(pos) *= (to_core ? len : 1.0 / len);
194178
}
195179
}
196180

0 commit comments

Comments
 (0)