当前位置: 首页>>代码示例>>Python>>正文


Python CameraModel.from_dict方法代码示例

本文整理汇总了Python中pymvg.camera_model.CameraModel.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python CameraModel.from_dict方法的具体用法?Python CameraModel.from_dict怎么用?Python CameraModel.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymvg.camera_model.CameraModel的用法示例。


在下文中一共展示了CameraModel.from_dict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_getters

# 需要导入模块: from pymvg.camera_model import CameraModel [as 别名]
# 或者: from pymvg.camera_model.CameraModel import from_dict [as 别名]
def test_getters():
    system1 = make_default_system()
    d = system1.to_dict()
    names1 = list(system1.get_camera_dict().keys())
    names2 = [cd['name'] for cd in d['camera_system']]
    assert set(names1)==set(names2)

    for idx in range(len(names1)):
        cam1 = system1.get_camera( names1[idx] )
        cam2 = CameraModel.from_dict(d['camera_system'][idx])
        assert cam1==cam2
开发者ID:strawlab,项目名称:pymvg,代码行数:13,代码来源:test_multi_camera_system.py

示例2: from_mcsc

# 需要导入模块: from pymvg.camera_model import CameraModel [as 别名]
# 或者: from pymvg.camera_model.CameraModel import from_dict [as 别名]

#.........这里部分代码省略.........
        all_Res = {}
        all_K = {}
        all_distortion = {}

        opj = os.path.join

        with open(opj(dirname,'camera_order.txt'),mode='r') as fd:
            cam_ids = fd.read().strip().split('\n')

        with open(os.path.join(dirname,'Res.dat'),'r') as res_fd:
            for i, cam_id in enumerate(cam_ids):
                fname = 'camera%d.Pmat.cal'%(i+1)
                pmat = np.loadtxt(opj(dirname,fname)) # 3 rows x 4 columns
                if do_normalize_pmat:
                    pmat_orig = pmat
                    pmat = normalize_M(pmat)
                all_Pmat[cam_id] = pmat
                all_Res[cam_id] = map(int,res_fd.readline().split())

        # load non linear parameters
        rad_files = [ f for f in os.listdir(dirname) if f.endswith('.rad') ]
        for cam_id_enum, cam_id in enumerate(cam_ids):
            filename = os.path.join(dirname,
                                    'basename%d.rad'%(cam_id_enum+1,))
            if os.path.exists(filename):
                K, distortion = parse_radfile(filename)
                all_K[cam_id] = K
                all_distortion[cam_id] = distortion
            else:
                if len(rad_files):
                    raise RuntimeError(
                        '.rad files present but none named "%s"'%filename)
                warnings.warn('no non-linear data (e.g. radial distortion) '
                              'in calibration for %s'%cam_id)
                all_K[cam_id] = None
                all_distortion[cam_id] = None

        cameras = []
        for cam_id in cam_ids:
            w,h = all_Res[cam_id]
            Pmat = all_Pmat[cam_id]
            M = Pmat[:,:3]
            K,R = my_rq(M)
            if not is_rotation_matrix(R):
                # RQ may return left-handed rotation matrix. Make right-handed.
                R2 = -R
                K2 = -K
                assert np.allclose(np.dot(K2,R2), np.dot(K,R))
                K,R = K2,R2

            P = np.zeros((3,4))
            P[:3,:3] = K
            KK = all_K[cam_id] # from rad file or None
            distortion = all_distortion[cam_id]

            # (ab)use PyMVG's rectification to do coordinate transform
            # for MCSC's undistortion.

            # The intrinsic parameters used for 3D -> 2D.
            ex = P[0,0]
            bx = P[0,2]
            Sx = P[0,3]
            ey = P[1,1]
            by = P[1,2]
            Sy = P[1,3]

            if KK is None:
                rect = np.eye(3)
                KK = P[:,:3]
            else:
                # Parameters used to define undistortion coordinates.
                fx = KK[0,0]
                fy = KK[1,1]
                cx = KK[0,2]
                cy = KK[1,2]

                rect = np.array([[ ex/fx,     0, (bx+Sx-cx)/fx ],
                                 [     0, ey/fy, (by+Sy-cy)/fy ],
                                 [     0,     0,       1       ]]).T

            if distortion is None:
                distortion = np.zeros((5,))

            C = center(Pmat)
            rot = R
            t = -np.dot(rot, C)[:,0]

            d = {'width':w,
                 'height':h,
                 'P':P,
                 'K':KK,
                 'R':rect,
                 'translation':t,
                 'Q':rot,
                 'D':distortion,
                 'name':cam_id,
                 }
            cam = CameraModel.from_dict(d)
            cameras.append( cam )
        return MultiCameraSystem( cameras=cameras )
开发者ID:aitatanit,项目名称:pymvg,代码行数:104,代码来源:multi_camera_system.py

示例3: from_pymvg_str

# 需要导入模块: from pymvg.camera_model import CameraModel [as 别名]
# 或者: from pymvg.camera_model.CameraModel import from_dict [as 别名]
 def from_pymvg_str(cls, buf):
     d = json.loads(buf)
     assert d['__pymvg_file_version__']=='1.0'
     cam_dict_list = d['camera_system']
     cams = [CameraModel.from_dict(cd) for cd in cam_dict_list]
     return MultiCameraSystem( cameras=cams )
开发者ID:aitatanit,项目名称:pymvg,代码行数:8,代码来源:multi_camera_system.py

示例4: from_dict

# 需要导入模块: from pymvg.camera_model import CameraModel [as 别名]
# 或者: from pymvg.camera_model.CameraModel import from_dict [as 别名]
 def from_dict(cls, d):
     cam_dict_list = d['camera_system']
     cams = [CameraModel.from_dict(cd) for cd in cam_dict_list]
     return MultiCameraSystem( cameras=cams )
开发者ID:aitatanit,项目名称:pymvg,代码行数:6,代码来源:multi_camera_system.py

示例5: check_dict_roundtrip

# 需要导入模块: from pymvg.camera_model import CameraModel [as 别名]
# 或者: from pymvg.camera_model.CameraModel import from_dict [as 别名]
def check_dict_roundtrip(cam_opts):
    cam = _build_test_camera(**cam_opts)
    d = cam.to_dict()
    cam2 = CameraModel.from_dict(d)
    assert cam==cam2
开发者ID:thinkerahead,项目名称:pymvg,代码行数:7,代码来源:test_camera_model.py


注:本文中的pymvg.camera_model.CameraModel.from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。