Python cv2.CV_16SC2 Examples
The following are 7
code examples of cv2.CV_16SC2().
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
.
Example #1
Source File: test-mvs.py From dfc2019 with MIT License | 6 votes |
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
Example #2
Source File: get-undistortion-maps.py From fsoco with Apache License 2.0 | 5 votes |
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"))
Example #3
Source File: test-mvs.py From dfc2019 with MIT License | 5 votes |
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
Example #4
Source File: main.py From fisheye with Apache License 2.0 | 5 votes |
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
Example #5
Source File: utils.py From PartiallyReversibleUnet with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #6
Source File: utils.py From PHiSeg-code with Apache License 2.0 | 5 votes |
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)))
Example #7
Source File: test-mvs.py From dfc2019 with MIT License | 4 votes |
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