本文整理匯總了Python中cv2.CALIB_CB_NORMALIZE_IMAGE屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.CALIB_CB_NORMALIZE_IMAGE屬性的具體用法?Python cv2.CALIB_CB_NORMALIZE_IMAGE怎麽用?Python cv2.CALIB_CB_NORMALIZE_IMAGE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cv2
的用法示例。
在下文中一共展示了cv2.CALIB_CB_NORMALIZE_IMAGE屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: find_chessboard
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CALIB_CB_NORMALIZE_IMAGE [as 別名]
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]
示例2: process_images
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CALIB_CB_NORMALIZE_IMAGE [as 別名]
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()
示例3: get_K_and_D
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CALIB_CB_NORMALIZE_IMAGE [as 別名]
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