def calibrate(target_type, optimization_type, calibration_data, camera_params, origin_offset=(0.0, 0.0, 0.0)): """ Calibrates a camera. @param target_type: The type of the target used for calibration. This can be either: - 'coplanar', in which all z-values for the calibration points are zero. - 'noncoplanar', in which some z-values for the calibration points must be non-zero. @param optimization_type: The type of optimization to perform. This can be either: - 'three-param', for optimization of only M{f}, M{Tz} and M{kappa1}. - 'full', for full optimization. @param calibration_data: A sequence of sequences containing calibration points. The sequence should consist of:: [ [ xs1, ys1, zs1, xi1, yi1 ], [ xs2, ys2, zs2, xi2, yi2 ], ... ... ... ... ... [ xsN, ysN, zsN, xiN, yiN ] ] where: - M{(xs, ys, zs)} are 3D space coordinates of the calibration points. - M{(xi, yi)} are corresponding 2D image space coordinates of the calibration points. @param camera_params: A dictionary mapping camera parameter names (stored as strings) to their values (which should be numbers). The class L{CameraParameters} is a utility class designed to be used in this position. @param origin_offset: An artificial offset that is added to the origin of the calibration data coordinates. This offset is later removed from the camera position as determined by the calibration. Shifting the origin may be useful since the Tsai method fails if the world space origin is near to the camera space origin or the camera space y axis. """ # add an origin offset to the camera position #xo,yo,zo = origin_offset xo, yo, zo = 0.0, 0.0, 0.0 def addOfs(c): return (c[0] + xo, c[1] + yo, c[2] + zo, c[3], c[4]) ofsCalData = list(map(addOfs, calibration_data)) # perform camera calibration if target_type == 'coplanar' and optimization_type == 'three-param': try: cp = pytsai._pytsai_coplanar_calibration(ofsCalData, camera_params) except RuntimeError as runtimeError: raise CalibrationError(str(runtimeError)) elif target_type == 'noncoplanar' and \ optimization_type == 'three-param': try: cp = pytsai._pytsai_noncoplanar_calibration( ofsCalData, camera_params) except RuntimeError as runtimeError: raise CalibrationError(str(runtimeError)) elif target_type == 'coplanar' and optimization_type == 'full': try: cp = pytsai._pytsai_coplanar_calibration_fo( ofsCalData, camera_params) except RuntimeError as runtimeError: raise CalibrationError(str(runtimeError)) elif target_type == 'noncoplanar' and optimization_type == 'full': try: cp = pytsai._pytsai_noncoplanar_calibration_fo( ofsCalData, camera_params) except RuntimeError as runtimeError: raise CalibrationError(str(runtimeError)) else: errstr = 'Unknown combination of target_type=\'%s\' and ' \ 'optimization_type=\'%s\'' % \ (target_type, optimization_type) raise CalibrationError(errstr) # remove the origin offset from the camera position ccp = CameraParameters(cp) #camorigin = ccp.world2camera((xo,yo,zo)) #ccp.Tx -= camorigin[0] #ccp.Ty -= camorigin[1] #ccp.Tz -= camorigin[2] # return the calculated camera parameters return ccp
try: cp = pytsai._pytsai_noncoplanar_calibration( ofsCalData, camera_params) except RuntimeError, (runtimeError): raise CalibrationError(str(runtimeError)) elif target_type == 'coplanar' and optimization_type == 'full': try: cp = pytsai._pytsai_coplanar_calibration_fo( ofsCalData, camera_params) except RuntimeError, (runtimeError): raise CalibrationError(str(runtimeError)) elif target_type == 'noncoplanar' and optimization_type == 'full': try: cp = pytsai._pytsai_noncoplanar_calibration_fo( ofsCalData, camera_params) except RuntimeError, (runtimeError): raise CalibrationError(str(runtimeError)) else: errstr = 'Unknown combination of target_type=\'%s\' and ' \ 'optimization_type=\'%s\'' % \ (target_type, optimization_type) raise CalibrationError(errstr) # remove the origin offset from the camera position ccp = CameraParameters(cp) #camorigin = ccp.world2camera((xo,yo,zo)) #ccp.Tx -= camorigin[0] #ccp.Ty -= camorigin[1] #ccp.Tz -= camorigin[2]
def calibrate(target_type, optimization_type, calibration_data, camera_params, origin_offset=(0.0,0.0,0.0)): """ Calibrates a camera. @param target_type: The type of the target used for calibration. This can be either: - 'coplanar', in which all z-values for the calibration points are zero. - 'noncoplanar', in which some z-values for the calibration points must be non-zero. @param optimization_type: The type of optimization to perform. This can be either: - 'three-param', for optimization of only M{f}, M{Tz} and M{kappa1}. - 'full', for full optimization. @param calibration_data: A sequence of sequences containing calibration points. The sequence should consist of:: [ [ xs1, ys1, zs1, xi1, yi1 ], [ xs2, ys2, zs2, xi2, yi2 ], ... ... ... ... ... [ xsN, ysN, zsN, xiN, yiN ] ] where: - M{(xs, ys, zs)} are 3D space coordinates of the calibration points. - M{(xi, yi)} are corresponding 2D image space coordinates of the calibration points. @param camera_params: A dictionary mapping camera parameter names (stored as strings) to their values (which should be numbers). The class L{CameraParameters} is a utility class designed to be used in this position. @param origin_offset: An artificial offset that is added to the origin of the calibration data coordinates. This offset is later removed from the camera position as determined by the calibration. Shifting the origin may be useful since the Tsai method fails if the world space origin is near to the camera space origin or the camera space y axis. """ # add an origin offset to the camera position #xo,yo,zo = origin_offset xo,yo,zo = 0.0,0.0,0.0 def addOfs(c): return (c[0]+xo, c[1]+yo, c[2]+zo, c[3], c[4]) ofsCalData = list(map(addOfs, calibration_data)) # perform camera calibration if target_type == 'coplanar' and optimization_type == 'three-param': try: cp = pytsai._pytsai_coplanar_calibration( ofsCalData, camera_params) except RuntimeError as runtimeError: raise CalibrationError(str(runtimeError)) elif target_type == 'noncoplanar' and \ optimization_type == 'three-param': try: cp = pytsai._pytsai_noncoplanar_calibration( ofsCalData, camera_params) except RuntimeError as runtimeError: raise CalibrationError(str(runtimeError)) elif target_type == 'coplanar' and optimization_type == 'full': try: cp = pytsai._pytsai_coplanar_calibration_fo( ofsCalData, camera_params) except RuntimeError as runtimeError: raise CalibrationError(str(runtimeError)) elif target_type == 'noncoplanar' and optimization_type == 'full': try: cp = pytsai._pytsai_noncoplanar_calibration_fo( ofsCalData, camera_params) except RuntimeError as runtimeError: raise CalibrationError(str(runtimeError)) else: errstr = 'Unknown combination of target_type=\'%s\' and ' \ 'optimization_type=\'%s\'' % \ (target_type, optimization_type) raise CalibrationError(errstr) # remove the origin offset from the camera position ccp = CameraParameters(cp) #camorigin = ccp.world2camera((xo,yo,zo)) #ccp.Tx -= camorigin[0] #ccp.Ty -= camorigin[1] #ccp.Tz -= camorigin[2] # return the calculated camera parameters return ccp