fitting.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:calcam 作者: euratom-software 项目源码 文件源码
def get_pupilpos(self,x_pixels=None,y_pixels=None,field=None,Coords='Display'):

        if x_pixels is not None or y_pixels is not None:
            if x_pixels is None or y_pixels is None:
                raise ValueError("X pixels and Y pixels must both be specified!")
            if np.shape(x_pixels) != np.shape(y_pixels):
                raise ValueError("X pixels array and Y pixels array must be the same size!")

            # Flatten everything and create output array        
            oldshape = np.shape(x_pixels)

            x_pixels = np.reshape(x_pixels,np.size(x_pixels),order='F')
            y_pixels = np.reshape(y_pixels,np.size(y_pixels),order='F')
            out = np.zeros(np.shape(x_pixels) + (3,))

            # Convert pixel coords if we need to
            if Coords.lower() == 'original':
                x_pixels,y_pixels = self.transform.original_to_display_coords(x_pixels,y_pixels)

            # Identify which sub-field each pixel is in
            pointfield = self.fieldmask[y_pixels.round().astype(int),x_pixels.round().astype(int)]
            if np.size(pointfield) == 1:
                pointfield = [pointfield]

            for i in range(np.size(x_pixels)):
                out[i,:] = self.get_pupilpos(field=pointfield[i])

            return np.reshape(out,oldshape + (3,),order='F')

        else:

            if field is None:
                if self.nfields == 1:
                    field = 0
                else:
                    raise Exception('This calibration has multiple sub-fields; you must specify a pixel location to get_pupilpos!')


            rotation_matrix = np.matrix(cv2.Rodrigues(self.fit_params[field].rvec)[0])
            CamPos = np.matrix(self.fit_params[field].tvec)
            CamPos = - (rotation_matrix.transpose() * CamPos)
            CamPos = np.array(CamPos)

            return np.array([CamPos[0][0],CamPos[1][0],CamPos[2][0]])


    # Get X and Y field of view of the camera (X and Y being horizontal and vertical of the detector)
    # Optional inputs: field - for cameras with split fields-of-view, the sub-field number to get the FOV of (int).
    #                  FullChipWithoutDistortion - ignores distortion and any split field-of-view, just returns the FOV
    #                                              for the full chip as if there was no distortion. Used in Calcam.Render() but probably not useful otherwise (bool).
    # Output: 2-element tuple with field of view in degrees: (horiz, vert) (tuple of floats)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号