def normalise(self,x,y,field):
if np.shape(x) != np.shape(y):
raise ValueError("X and Y input arrays must be the same size!")
if self.fit_params[field].model == 'fisheye' and opencv_major_version < 3:
raise Exception('Fisheye model distortion calculation requires OpenCV 3 or newer! Your version is ' + cv2.__version__)
# Flatten everything and create output array
oldshape = np.shape(x)
x = np.reshape(x,np.size(x),order='F')
y = np.reshape(y,np.size(y),order='F')
input_points = np.zeros([x.size,1,2])
for point in range(len(x)):
input_points[point,0,0] = x[point]
input_points[point,0,1] = y[point]
if self.fit_params[field].model == 'perspective':
undistorted = cv2.undistortPoints(input_points,self.fit_params[field].cam_matrix,self.fit_params[field].kc)
elif self.fit_params[field].model == 'fisheye':
undistorted = cv2.fisheye.undistortPoints(input_points,self.fit_params[field].cam_matrix,self.fit_params[field].kc)
undistorted = np.swapaxes(undistorted,0,1)[0]
return np.reshape(undistorted[:,0],oldshape,order='F') , np.reshape(undistorted[:,1],oldshape,order='F')
# Get the sight-line direction(s) for given pixel coordinates, as unit vector(s) in the lab frame.
# Input: x_pixel and y_pixel - array-like, x and y pixel coordinates (floats or arrays/lists of floats)
# Optional inputs: ForceField - for split field cameras, get the sight line direction as if the pixel
# was part of the specified subfield, even if it isn't really (int)
# Coords - whether the input x_pixel and y_pixel values are in display or original
# coordimates (default Display; string either 'Display' or 'Original')
# Output: Numpy array with 1 more dimension than the input x_pixels and y_pixels, but otherwise
# the same size and shape. The extra dimension indexes the 3 vector components, 0 = X, 1 = Y, 2 = Z.
# This is a unit vector in the CAD model coordinate system.
评论列表
文章目录