Python cv2.CALIB_CB_NORMALIZE_IMAGE Examples
The following are 3
code examples of cv2.CALIB_CB_NORMALIZE_IMAGE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: calibrate.py From depthai with MIT License | 5 votes |
def find_chessboard(frame): chessboard_flags = cv2.CALIB_CB_ADAPTIVE_THRESH + cv2.CALIB_CB_FAST_CHECK + cv2.CALIB_CB_NORMALIZE_IMAGE small_frame = cv2.resize(frame, (0, 0), fx=0.3, fy=0.3) return cv2.findChessboardCorners(small_frame, (9, 6), chessboard_flags)[0] and \ cv2.findChessboardCorners(frame, (9, 6), chessboard_flags)[0]
Example #2
Source File: calibration_utils.py From depthai with MIT License | 4 votes |
def process_images(self, filepath): """Read images, detect corners, refine corners, and save data.""" # Arrays to store object points and image points from all the images. self.objpoints = [] # 3d point in real world space self.imgpoints_l = [] # 2d points in image plane. self.imgpoints_r = [] # 2d points in image plane. self.calib_successes = [] # polygon ids of left/right image sets with checkerboard corners. images_left = glob.glob(filepath + "/left/*") images_right = glob.glob(filepath + "/right/*") images_left.sort() images_right.sort() print("\nAttempting to read images for left camera from dir: " + filepath + "/left/") print("Attempting to read images for right camera from dir: " + filepath + "/right/") assert len(images_left) != 0, "ERROR: Images not read correctly, check directory" assert len(images_right) != 0, "ERROR: Images not read correctly, check directory" for image_left, image_right in zip(images_left, images_right): img_l = cv2.imread(image_left, 0) img_r = cv2.imread(image_right, 0) assert img_l is not None, "ERROR: Images not read correctly" assert img_r is not None, "ERROR: Images not read correctly" print("Finding chessboard corners for %s and %s..." % (os.path.basename(image_left), os.path.basename(image_right))) start_time = time.time() # Find the chess board corners flags = 0 flags |= cv2.CALIB_CB_ADAPTIVE_THRESH flags |= cv2.CALIB_CB_NORMALIZE_IMAGE ret_l, corners_l = cv2.findChessboardCorners(img_l, (9, 6), flags) ret_r, corners_r = cv2.findChessboardCorners(img_r, (9, 6), flags) # termination criteria self.criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS, 30, 0.001) # if corners are found in both images, refine and add data if ret_l and ret_r: self.objpoints.append(self.objp) rt = cv2.cornerSubPix(img_l, corners_l, (5, 5), (-1, -1), self.criteria) self.imgpoints_l.append(corners_l) rt = cv2.cornerSubPix(img_r, corners_r, (5, 5), (-1, -1), self.criteria) self.imgpoints_r.append(corners_r) self.calib_successes.append(polygon_from_image_name(image_left)) print("\t[OK]. Took %i seconds." % (round(time.time() - start_time, 2))) else: print("\t[ERROR] - Corners not detected. Took %i seconds." % (round(time.time() - start_time, 2))) self.img_shape = img_r.shape[::-1] print(str(len(self.objpoints)) + " of " + str(len(images_left)) + " images being used for calibration") self.ensure_valid_images()
Example #3
Source File: main.py From fisheye with Apache License 2.0 | 4 votes |
def get_K_and_D(checkerboard, imgsPath): CHECKERBOARD = checkerboard subpix_criteria = (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1) calibration_flags = cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC+cv2.fisheye.CALIB_CHECK_COND+cv2.fisheye.CALIB_FIX_SKEW objp = np.zeros((1, CHECKERBOARD[0]*CHECKERBOARD[1], 3), np.float32) objp[0,:,:2] = np.mgrid[0:CHECKERBOARD[0], 0:CHECKERBOARD[1]].T.reshape(-1, 2) _img_shape = None objpoints = [] imgpoints = [] images = glob.glob(imgsPath + '/*.png') for fname in images: img = cv2.imread(fname) if _img_shape == None: _img_shape = img.shape[:2] else: assert _img_shape == img.shape[:2], "All images must share the same size." gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ret, corners = cv2.findChessboardCorners(gray, CHECKERBOARD,cv2.CALIB_CB_ADAPTIVE_THRESH+cv2.CALIB_CB_FAST_CHECK+cv2.CALIB_CB_NORMALIZE_IMAGE) if ret == True: objpoints.append(objp) cv2.cornerSubPix(gray,corners,(3,3),(-1,-1),subpix_criteria) imgpoints.append(corners) N_OK = len(objpoints) K = np.zeros((3, 3)) D = np.zeros((4, 1)) rvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(N_OK)] tvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(N_OK)] rms, _, _, _, _ = cv2.fisheye.calibrate( objpoints, imgpoints, gray.shape[::-1], K, D, rvecs, tvecs, calibration_flags, (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6) ) DIM = _img_shape[::-1] print("Found " + str(N_OK) + " valid images for calibration") print("DIM=" + str(_img_shape[::-1])) print("K=np.array(" + str(K.tolist()) + ")") print("D=np.array(" + str(D.tolist()) + ")") return DIM, K, D