导出RealityCapture相机参数

2020-03-29  本文已影响0人  Reyuwei
  1. 在 reality capture根目录下calibration.xml文件中添加
 <format mask="*.lst" desc="CmpMvs _KRT matrices" writer="cvs" undistortImages="0" undistortPrincipal="0">
    <hint type="continue" strId="8351" >Files with the camera matrices will be stored next to the corresponding input file. Do you want to continue?</hint>
        <body>$ExportCameras($(imagePath)$(imageName)$(imageExt)
$WriteFile("$(imagePath)$(imageName)_KRT.txt",$(f*scale) 0 $(px*scale+0.5*width) 0
0 $(f*scale) $(py*scale+0.5*height) 0
0 0 1 0
$(R00) $(R01) $(R02) $(tx)
$(R10) $(R11) $(R12) $(ty)
$(R20) $(R21) $(R22) $(tz)))</body>                                                              
    </format>
  1. 在RealityCapture中选择
  1. 相机参数会保存到
    imgname_KRT.txt文件中,每个文件表示一个相机的内参和外参

  2. 读取示例

class Camera:
    def __init__(self, krtfile, name=""):
        mat = np.loadtxt(krtfile)
        self.K = mat[0:3, 0:3]
        self.Rt = mat[3:, :]
        self.name = name
    
    @property
    def projection(self):
        return self.K.dot(self.extrinsics)

    @property
    def extrinsics(self):
        return self.Rt

    def project3dpoint(self, point):
        point = np.array(point)
        assert(point.shape[0] == 3)
        projection = np.matmul(self.projection, np.hstack([point, 1]).reshape(4, 1))
        projection = projection / projection[-1]
        return np.array([int(projection[0]),int(projection[1])])

def readCRKRT(cr_camera_projection):
    print("Loading camera projection matrix from " + str(cr_camera_projection))    
    files = os.listdir(str(cr_camera_projection))
    cameras = []
    for f in files:
        if "_KRT.txt" in f:
            cam_proj_file = cr_camera_projection / f
            cameras.append(Camera(cam_proj_file, f))
    return cameras

from pathlib import *
camerapath = Path("E:\cr_folder")
cameras = readCRKRT(camerapath)
print(cameras[0].K)
print(cameras[0].projection)

点云重投影效果

原图(没有去畸变)
点云重投影
上一篇下一篇

猜你喜欢

热点阅读