本文整理匯總了Python中cv2.CV_16SC2屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.CV_16SC2屬性的具體用法?Python cv2.CV_16SC2怎麽用?Python cv2.CV_16SC2使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cv2
的用法示例。
在下文中一共展示了cv2.CV_16SC2屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rectify_images_float
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16SC2 [as 別名]
def rectify_images_float(img1, x1, img2, x2, K, d, F, shearing=False):
imsize = (img1.shape[1], img1.shape[0])
H1, H2, rms, max_error = epipolar.rectify_uncalibrated(x1, x2, F, imsize)
if shearing:
S = epipolar.rectify_shearing(H1, H2, imsize)
H1 = S.dot(H1)
rH = la.inv(K).dot(H1).dot(K)
lH = la.inv(K).dot(H2).dot(K)
map1x, map1y = cv2.initUndistortRectifyMap(K, d, rH, K, imsize, cv.CV_16SC2)
map2x, map2y = cv2.initUndistortRectifyMap(K, d, lH, K, imsize, cv.CV_16SC2)
rimg1 = cv2.remap(img1, map1x, map1y,
interpolation=cv.INTER_NEAREST,
borderMode=cv2.BORDER_CONSTANT,
borderValue=(0, 0, 0, 0))
rimg2 = cv2.remap(img2, map2x, map2y,
interpolation=cv.INTER_NEAREST,
borderMode=cv2.BORDER_CONSTANT,
borderValue=(0, 0, 0, 0))
return rimg1, rimg2
# get NITF metadata that we embedded in the GeoTIFF header
示例2: main
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16SC2 [as 別名]
def main():
basler_undistorted = pickle.load(open("basler_pickle.p", "rb"))
#objects = []
#with (open("./basler_pickle.p", "rb")) as openfile:
# while True:
# try:
# basler_undistorted.append(pickle.load(openfile))
# except EOFError:
# break
image_width = 1280
image_height = 1024
#print(basler_undistorted)
cam_mtx = basler_undistorted["mtx"]
cam_dist = basler_undistorted["dist"]
rvecs = basler_undistorted["rvecs"]
tvecs = basler_undistorted["tvecs"]
#imageSize = image_height * image_width
imageSize = ( image_height, image_width )
#getOptimal...Mtx(cameraMatrix, distCoeffs, imageSize, alpha[, newImgSize[, centerPrincipalPoint]]) -> retval, validPixROI
# Doesn't take Rect of validPixROI, contrary to the cpp method
new_cam_mtx, valid_roi = cv.getOptimalNewCameraMatrix(cam_mtx, cam_dist, imageSize, 1, imageSize, 1)
# getOptimalNewCameraMatrix() possibly not working like in cpp
#map1, map2 = cv.initUndistortRectifyMap(cam_mtx, cam_dist, np.eye(3), new_cam_mtx, imageSize, cv.CV_16SC2);
map1, map2 = cv.initUndistortRectifyMap(cam_mtx, cam_dist, np.eye(3), cam_mtx, imageSize, cv.CV_16SC2);
# map1 and map2 can be used together with cv.remap() for efficient real-time undistortion
# Only need to be calculated once.
maps = { "map1": map1, "map2": map2 }
pickle.dump( maps, open("maps.p", "wb"))
示例3: rectify_images_rgb
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16SC2 [as 別名]
def rectify_images_rgb(img1, x1, img2, x2, K, d, F, shearing=False):
imsize = (img1.shape[1], img1.shape[0])
H1, H2, rms, max_error = epipolar.rectify_uncalibrated(x1, x2, F, imsize)
if shearing:
S = epipolar.rectify_shearing(H1, H2, imsize)
H1 = S.dot(H1)
rH = la.inv(K).dot(H1).dot(K)
lH = la.inv(K).dot(H2).dot(K)
# TODO: lRect or rRect for img1/img2 ??
map1x, map1y = cv2.initUndistortRectifyMap(K, d, rH, K, imsize, cv.CV_16SC2)
map2x, map2y = cv2.initUndistortRectifyMap(K, d, lH, K, imsize, cv.CV_16SC2)
rimg1 = cv2.remap(img1, map1x, map1y,
interpolation=cv.INTER_CUBIC,
borderMode=cv2.BORDER_CONSTANT,
borderValue=(0, 0, 0))
rimg2 = cv2.remap(img2, map2x, map2y,
interpolation=cv.INTER_CUBIC,
borderMode=cv2.BORDER_CONSTANT,
borderValue=(0, 0, 0))
return rimg1, rimg2, rms, max_error
# rectify a floating point image pair based on the Fundamental matrix
# use this for XYZ images
示例4: undistort
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16SC2 [as 別名]
def undistort(img_path,K,D,DIM,scale=0.6,imshow=False):
img = cv2.imread(img_path)
dim1 = img.shape[:2][::-1] #dim1 is the dimension of input image to un-distort
assert dim1[0]/dim1[1] == DIM[0]/DIM[1], "Image to undistort needs to have same aspect ratio as the ones used in calibration"
if dim1[0]!=DIM[0]:
img = cv2.resize(img,DIM,interpolation=cv2.INTER_AREA)
Knew = K.copy()
if scale:#change fov
Knew[(0,1), (0,1)] = scale * Knew[(0,1), (0,1)]
map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), Knew, DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
if imshow:
cv2.imshow("undistorted", undistorted_img)
return undistorted_img
示例5: dense_image_warp
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16SC2 [as 別名]
def dense_image_warp(im, dx, dy, interp=cv2.INTER_LINEAR):
map_x, map_y = deformation_to_transformation(dx, dy)
do_optimization = (interp == cv2.INTER_LINEAR)
# The following command converts the maps to compact fixed point representation
# this leads to a ~20% increase in speed but could lead to accuracy losses
# Can be uncommented
if do_optimization:
map_x, map_y = cv2.convertMaps(map_x, map_y, dstmap1type=cv2.CV_16SC2)
remapped = cv2.remap(im, map_x, map_y, interpolation=interp, borderMode=cv2.BORDER_REFLECT) #borderValue=float(np.min(im)))
if im.ndim > remapped.ndim:
remapped = np.expand_dims(remapped, im.ndim)
return remapped
示例6: dense_image_warp
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16SC2 [as 別名]
def dense_image_warp(im, dx, dy, interp=cv2.INTER_LINEAR, do_optimisation=True):
map_x, map_y = deformation_to_transformation(dx, dy)
# The following command converts the maps to compact fixed point representation
# this leads to a ~20% increase in speed but could lead to accuracy losses
# Can be uncommented
if do_optimisation:
map_x, map_y = cv2.convertMaps(map_x, map_y, dstmap1type=cv2.CV_16SC2)
return cv2.remap(im, map_x, map_y, interpolation=interp, borderMode=cv2.BORDER_REFLECT) #borderValue=float(np.min(im)))
示例7: rectify_images
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16SC2 [as 別名]
def rectify_images(img1, x1, img2, x2, K, d, F, shearing=False):
imsize = (img1.shape[1], img1.shape[0])
H1, H2, rms, max_error = epipolar.rectify_uncalibrated(x1, x2, F, imsize)
if shearing:
S = epipolar.rectify_shearing(H1, H2, imsize)
H1 = S.dot(H1)
rH = la.inv(K).dot(H1).dot(K)
lH = la.inv(K).dot(H2).dot(K)
# check for y parallax
max_yparallax = get_y_parallax(x1, x2, rH, lH, imsize)
# TODO: lRect or rRect for img1/img2 ??
map1x, map1y = cv2.initUndistortRectifyMap(K, d, rH, K, imsize,
cv.CV_16SC2)
map2x, map2y = cv2.initUndistortRectifyMap(K, d, lH, K, imsize,
cv.CV_16SC2)
# Convert the images to RGBA (add an axis with 4 values)
img1 = np.tile(img1[:, :, np.newaxis], [1, 1, 4])
img1[:, :, 3] = 255
img2 = np.tile(img2[:, :, np.newaxis], [1, 1, 4])
img2[:, :, 3] = 255
rimg1 = cv2.remap(img1, map1x, map1y,
interpolation=cv.INTER_NEAREST,
borderMode=cv2.BORDER_CONSTANT,
borderValue=(0, 0, 0, 0))
rimg2 = cv2.remap(img2, map2x, map2y,
interpolation=cv.INTER_NEAREST,
borderMode=cv2.BORDER_CONSTANT,
borderValue=(0, 0, 0, 0))
# Put a red background on the invalid values
# TODO: Return a mask for valid/invalid values
# TODO: There is aliasing happening on the images border. We should
# invalidate a margin around the border so we're sure we have only valid
# pixels
rimg1[rimg1[:, :, 3] == 0, :] = (255, 0, 0, 255)
rimg2[rimg2[:, :, 3] == 0, :] = (255, 0, 0, 255)
return rimg1, rimg2, rms, max_error, lH, rH, max_yparallax
# rectify an image pair based on the Fundamental matrix