示例#1
0
    def __init__(self, calibration_image_size, focal_length_pixels,
                  optical_center_pixels, lens_distortion_radial):
        '''
           Format for parameters:
                focal_length_pixels        = (720.511045, 724.498871),
                optical_center_pixels      = (324.277843, 236.260833),
                lens_distortion_radial     = (-0.428665, 0.300025, -0.230655),
        '''
        self.calibration_image_size     =  calibration_image_size     
        self.focal_length_pixels        =  focal_length_pixels           
        self.optical_center_pixels      =  optical_center_pixels        
        self.lens_distortion_radial     =  lens_distortion_radial       
        self.intrinsic_mat        =    np.array([[focal_length_pixels[0], 0,                        optical_center_pixels[0]],
 			                                     [0,                        focal_length_pixels[1], optical_center_pixels[1]],
			                                     [0,                        0,                      1]]) 
        self.inv_intrinsic_mat    = np.linalg.inv(np.matrix(self.intrinsic_mat)) 

        self.intrinsic_mat_cv              = ut.numpymat2cvmat(self.intrinsic_mat) 
        self.inv_intrinsic_mat_cv          = ut.numpymat2cvmat(self.inv_intrinsic_mat)
        self.lens_distortion_radial_cv     = cv.cvCreateMat(4, 1, cv.CV_32FC1)
        self.lens_distortion_radial_cv[0,0] = lens_distortion_radial[0]
        self.lens_distortion_radial_cv[1,0] = lens_distortion_radial[1]
        self.lens_distortion_radial_cv[2,0] = 0
        #self.lens_distortion_radial_cv[2,0] = lens_distortion_radial[2]
        self.lens_distortion_radial_cv[3,0] = 0
        self.temp = None

        self.mapx = cv.cvCreateMat(int(calibration_image_size[1]), int(calibration_image_size[0]), cv.CV_32FC1)
        self.mapy = cv.cvCreateMat(int(calibration_image_size[1]), int(calibration_image_size[0]), cv.CV_32FC1)
        cv.cvInitUndistortMap(self.intrinsic_mat_cv, self.lens_distortion_radial_cv, self.mapx, self.mapy)
示例#2
0
    def __init__(self, calibration_image_size, focal_length_pixels,
                 optical_center_pixels, lens_distortion_radial):
        '''
           Format for parameters:
                focal_length_pixels        = (720.511045, 724.498871),
                optical_center_pixels      = (324.277843, 236.260833),
                lens_distortion_radial     = (-0.428665, 0.300025, -0.230655),
        '''
        self.calibration_image_size = calibration_image_size
        self.focal_length_pixels = focal_length_pixels
        self.optical_center_pixels = optical_center_pixels
        self.lens_distortion_radial = lens_distortion_radial
        self.intrinsic_mat = np.array(
            [[focal_length_pixels[0], 0, optical_center_pixels[0]],
             [0, focal_length_pixels[1], optical_center_pixels[1]], [0, 0, 1]])
        self.inv_intrinsic_mat = np.linalg.inv(np.matrix(self.intrinsic_mat))

        self.intrinsic_mat_cv = ut.numpymat2cvmat(self.intrinsic_mat)
        self.inv_intrinsic_mat_cv = ut.numpymat2cvmat(self.inv_intrinsic_mat)
        self.lens_distortion_radial_cv = cv.cvCreateMat(4, 1, cv.CV_32FC1)
        self.lens_distortion_radial_cv[0, 0] = lens_distortion_radial[0]
        self.lens_distortion_radial_cv[1, 0] = lens_distortion_radial[1]
        self.lens_distortion_radial_cv[2, 0] = 0
        #self.lens_distortion_radial_cv[2,0] = lens_distortion_radial[2]
        self.lens_distortion_radial_cv[3, 0] = 0
        self.temp = None

        self.mapx = cv.cvCreateMat(int(calibration_image_size[1]),
                                   int(calibration_image_size[0]), cv.CV_32FC1)
        self.mapy = cv.cvCreateMat(int(calibration_image_size[1]),
                                   int(calibration_image_size[0]), cv.CV_32FC1)
        cv.cvInitUndistortMap(self.intrinsic_mat_cv,
                              self.lens_distortion_radial_cv, self.mapx,
                              self.mapy)
示例#3
0
文件: camera.py 项目: wklharry/hrl
def rodrigues(vec):
    cvvec = ut.numpymat2cvmat(vec)
    dst = cv.CreateMat(3, 3, cv.CV_32FC1)
    cv.Rodrigues2(cvvec, dst)
    return ut.cvmat2numpymat(dst).T
示例#4
0
def rodrigues(vec):
    cvvec = ut.numpymat2cvmat(vec)
    dst   = cv.cvCreateMat(3,3,cv.CV_32FC1)
    cv.cvRodrigues2(cvvec, dst)
    return ut.cvmat2numpymat(dst).T
示例#5
0
        import util

        import camera_config as cc
        cp = cc.camera_parameters[camera_name]

        size = (int(cp['calibration_image_width']), int(cp['calibration_image_height']))
        color = cp['color']
        intrinsic_cvmat = cvCreateMat(3,3,cv.CV_32FC1)
        distortion_cvmat = cvCreateMat(1,4,cv.CV_32FC1)

        imat_np = np.array([[cp['focal_length_x_in_pixels'],0,
                             cp['optical_center_x_in_pixels']],
                            [0,cp['focal_length_y_in_pixels'],
                             cp['optical_center_y_in_pixels']],
                            [0,0,1]])
        intrinsic_cvmat = util.numpymat2cvmat(imat_np)

        dmat_np = np.array([[cp['lens_distortion_radial_1'],
                             cp['lens_distortion_radial_2'],
                             cp['lens_distortion_tangential_1'],
                             cp['lens_distortion_tangential_2']]])

        distortion_cvmat = util.numpymat2cvmat(dmat_np)
        undistort_mapx = cvCreateImage(size, IPL_DEPTH_32F, 1)
        undistort_mapy = cvCreateImage(size, IPL_DEPTH_32F, 1)
        cvInitUndistortMap(intrinsic_cvmat, distortion_cvmat,
                           undistort_mapx, undistort_mapy)

        if color == True:
            undistort_image = cvCreateImage(size, IPL_DEPTH_8U, 3)
        else:
示例#6
0
        cp = cc.camera_parameters[camera_name]

        size = (int(cp["calibration_image_width"]), int(cp["calibration_image_height"]))
        color = cp["color"]
        intrinsic_cvmat = cvCreateMat(3, 3, cv.CV_32FC1)
        distortion_cvmat = cvCreateMat(1, 4, cv.CV_32FC1)

        imat_np = np.array(
            [
                [cp["focal_length_x_in_pixels"], 0, cp["optical_center_x_in_pixels"]],
                [0, cp["focal_length_y_in_pixels"], cp["optical_center_y_in_pixels"]],
                [0, 0, 1],
            ]
        )
        intrinsic_cvmat = util.numpymat2cvmat(imat_np)

        dmat_np = np.array(
            [
                [
                    cp["lens_distortion_radial_1"],
                    cp["lens_distortion_radial_2"],
                    cp["lens_distortion_tangential_1"],
                    cp["lens_distortion_tangential_2"],
                ]
            ]
        )

        distortion_cvmat = util.numpymat2cvmat(dmat_np)
        undistort_mapx = cvCreateImage(size, IPL_DEPTH_32F, 1)
        undistort_mapy = cvCreateImage(size, IPL_DEPTH_32F, 1)