论文:CVPR 2018 paper — Texture Mapping for 3D Reconstruction with RGB-D Sensor
github链接:https://github.com/fdp0525/G2LTex
G2LTex从三维重建到纹理贴图
一、reality capture重建
1.导入图片;
2.图像对其;
3.开始(重建)。
二、导出reality capture数据
导出mesh
1.点击网格;
2.选择.ply;
3.按默认,点确定;
导出相机外参
在RC根目录下找到这个文件,打开。
加入如下代码
<format mask="*.txt" desc="G2LTex_external" writer="cvs" requiresEqualResolution="1" undistortImages="1" undistortPrincipal="1">
<body>$ExportCameras($(tx:g) $(ty:g) $(tz:g) $(R00:g) $(R01:g) $(R02:g) $(R10:g) $(R11:g) $(R12:g) $(R20:g) $(R21:g) $(R22:g)
)</body>
</format>
save xml文件。
注:tx,ty,tz是平移矩阵,r00,…,r22是旋转矩阵,f * scale是fx,fy,(px * scale+0.5 * width)是cx,(py * scale+0.5*height)是cy。
然后,按图中步骤操作。
按需调整,确定。
注,可能需要点全选。
导出相机内参
同上,calibration.xml里加入如下代码
<format mask="*.txt" desc="internal" writer="cvs" requiresEqualResolution="1" undistortImages="1" undistortPrincipal="1">
<body>
$ExportCameras($(index:d) $(f*scale:g) $(px*scale+0.5*width) $(py*scale+0.5*height)
)
</body>
</format>
同上,定位,输出。
三、处理数据
目标:
拆分external.txt
将如下代码编译运行,注意更改路径。
open_diff = open('C:\\Users\\艾伦\\Desktop\\G2LTex_data\\stone\\external\\external.txt', 'r') # 源文本文件
diff_line = open_diff.readlines()
line_list = []
for line in diff_line:
line_list.append(line)
count = len(line_list) # 文件行数
print('源文件数据行数:',count)
# 切分diff
diff_match_split = [line_list[i:i+1] for i in range(0,len(line_list),1)]# 每个文件的数据行数
# 将切分的写入多个txt中
for i,j in zip(range(0,int(count/1+1)),range(0,int(count/1+1))): # 写入txt,计算需要写入的文件数
with open('C:\\Users\\艾伦\\Desktop\\G2LTex_data\\stone\\external\\color_%02d.txt'% j,'w+') as temp:
for line in diff_match_split[i]:
temp.write(line)
print('拆分后文件的个数:',i+1)
会多一个,记得删掉。
批量更换文件名
ubtunu下:
gedit rename.sh
改名脚本如下,根据实际需要修改:
#!/bin/bash
# .txt to .cam
rename 's/txt/cam/' *.txt
# .png文件换名
for files in `ls *.png`
do
hname="depth_"
# 截取文件名
fname=${files:7:9}
# 拼接成文件名
filename=$hname$fname
# 更改文件名
mv $files $filename
echo $filename
done
# .jpg文件换名
for files in `ls *.jpg`
do
hname="color_"
# 截取文件名
fname=${files:3:6}
# 截取文件的后四个字符
#bname=${files:0-4}
# 拼接成文件名
filename=$hname$fname
# 更改文件名
mv $files $filename
echo $filename
done
四、将内参填入Config/config.yml
查看internal.txt。
f * scale是fx,fy,(px * scale+0.5 * width)是cx,(py * scale+0.5*height)是cy。
将内参填入Config/config.yml。