def __init__(self, x, y, K, d, camid=0, visualize=False, debug=False):
# Initialize multiprocessing.Process parent
multiprocessing.Process.__init__(self)
# Exit event for stopping process
self._exit = multiprocessing.Event()
# Event that is set, everytime an image has been unwarped
self.newframe_event = multiprocessing.Event()
# Event that pauses the main loop if set
self._pause_event = multiprocessing.Event()
# Defines whether to visualize the camera output
self._visualize = visualize
# Switches debugging mode
self._debug = debug
# Some variable for storing the time of the last frame
self._oldtime = time.time()
# Set camera parameters
self._cam_device_id = camid # Get camera ID
self._x = x # Get width
self._y = y # Get height
# An empty array in shared memory to store the current image frame
self._currentframe = sharedmem.empty((y, x), dtype='uint8')
# Define camera matrix K
self._K = K
# Define distortion coefficients d
self._d = d
# Setup camera object using OpenCV
self._cam = cv2.VideoCapture(self._cam_device_id)
self._cam.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, self._x)
self._cam.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, self._y)
# Generate optimal camera matrix
self._newcameramatrix, self._roi = cv2.getOptimalNewCameraMatrix(self._K, self._d, (self._x, self._y), 0)
# Generate LUTs for undistortion
self._mapx, self._mapy = cv2.initUndistortRectifyMap(self._K, self._d, None, self._newcameramatrix,
(self._x, self._y), 5)
评论列表
文章目录