美文网首页
导出RealityCapture相机参数

导出RealityCapture相机参数

作者: Reyuwei | 来源:发表于2020-03-29 14:41 被阅读0次
    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中选择
    • alignment
      • export
        • registration
          • 下拉框选择CmpMvs _KRT matrices
    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)
    

    点云重投影效果

    原图(没有去畸变)
    点云重投影

    相关文章

      网友评论

          本文标题:导出RealityCapture相机参数

          本文链接:https://www.haomeiwen.com/subject/lfxuuhtx.html