本文整理汇总了Python中cv2.BORDER_DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.BORDER_DEFAULT属性的具体用法?Python cv2.BORDER_DEFAULT怎么用?Python cv2.BORDER_DEFAULT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.BORDER_DEFAULT属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sobelOperT
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def sobelOperT(self, img, blursize, morphW, morphH):
'''
No different with sobelOper ?
'''
blur = cv2.GaussianBlur(img, (blursize, blursize), 0, 0, cv2.BORDER_DEFAULT)
if len(blur.shape) == 3:
gray = cv2.cvtColor(blur, cv2.COLOR_RGB2GRAY)
else:
gray = blur
x = cv2.Sobel(gray, cv2.CV_16S, 1, 0, 3)
absX = cv2.convertScaleAbs(x)
grad = cv2.addWeighted(absX, 1, 0, 0, 0)
_, threshold = cv2.threshold(grad, 0, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)
element = cv2.getStructuringElement(cv2.MORPH_RECT, (morphW, morphH))
threshold = cv2.morphologyEx(threshold, cv2.MORPH_CLOSE, element)
return threshold
示例2: inpaint
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def inpaint(self, missing_value=0):
"""
Inpaint missing values in depth image.
:param missing_value: Value to fill in teh depth image.
"""
# cv2 inpainting doesn't handle the border properly
# https://stackoverflow.com/questions/25974033/inpainting-depth-map-still-a-black-image-border
self.img = cv2.copyMakeBorder(self.img, 1, 1, 1, 1, cv2.BORDER_DEFAULT)
mask = (self.img == missing_value).astype(np.uint8)
# Scale to keep as float, but has to be in bounds -1:1 to keep opencv happy.
scale = np.abs(self.img).max()
self.img = self.img.astype(np.float32) / scale # Has to be float32, 64 not supported.
self.img = cv2.inpaint(self.img, mask, 1, cv2.INPAINT_NS)
# Back to original size and value range.
self.img = self.img[1:-1, 1:-1]
self.img = self.img * scale
示例3: resize_to_desired
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def resize_to_desired(input_img):
h = input_img.shape[0]
if h < 20: # pad the image to 20 or 21 pixels height if it is too short
border = math.ceil((20 - h) / 2)
new_img = cv2.copyMakeBorder(input_img, top=border, bottom=border, left=0, right=0,
borderType=cv2.BORDER_DEFAULT)
else:
new_img = input_img
return cv2.resize(new_img, (CLS_IMG_WIDTH, CLS_IMG_HEIGHT))
示例4: sobelOper
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def sobelOper(self, img, blursize, morphW, morphH):
blur = cv2.GaussianBlur(img, (blursize, blursize), 0, 0, cv2.BORDER_DEFAULT)
if len(blur.shape) == 3:
gray = cv2.cvtColor(blur, cv2.COLOR_RGB2GRAY)
else:
gray = blur
x = cv2.Sobel(gray, cv2.CV_16S, 1, 0, ksize=3, scale=1, delta=0, borderType=cv2.BORDER_DEFAULT)
absX = cv2.convertScaleAbs(x)
grad = cv2.addWeighted(absX, 1, 0, 0, 0)
_, threshold = cv2.threshold(grad, 0, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)
element = cv2.getStructuringElement(cv2.MORPH_RECT, (morphW, morphH))
threshold = cv2.morphologyEx(threshold, cv2.MORPH_CLOSE, element)
return threshold
示例5: gradients
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def gradients(self):
"""
Compute gradients of the depth image using Sobel filtesr.
:return: Gradients in X direction, Gradients in Y diretion, Magnitude of XY gradients.
"""
grad_x = cv2.Sobel(self.img, cv2.CV_64F, 1, 0, borderType=cv2.BORDER_DEFAULT)
grad_y = cv2.Sobel(self.img, cv2.CV_64F, 0, 1, borderType=cv2.BORDER_DEFAULT)
grad = np.sqrt(grad_x ** 2 + grad_y ** 2)
return DepthImage(grad_x), DepthImage(grad_y), DepthImage(grad)
示例6: process_depth_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def process_depth_image(depth, crop_size, out_size=300, return_mask=False, crop_y_offset=0):
imh, imw = depth.shape
with TimeIt('1'):
# Crop.
depth_crop = depth[(imh - crop_size) // 2 - crop_y_offset:(imh - crop_size) // 2 + crop_size - crop_y_offset,
(imw - crop_size) // 2:(imw - crop_size) // 2 + crop_size]
# depth_nan_mask = np.isnan(depth_crop).astype(np.uint8)
# Inpaint
# OpenCV inpainting does weird things at the border.
with TimeIt('2'):
depth_crop = cv2.copyMakeBorder(depth_crop, 1, 1, 1, 1, cv2.BORDER_DEFAULT)
depth_nan_mask = np.isnan(depth_crop).astype(np.uint8)
with TimeIt('3'):
depth_crop[depth_nan_mask==1] = 0
with TimeIt('4'):
# Scale to keep as float, but has to be in bounds -1:1 to keep opencv happy.
depth_scale = np.abs(depth_crop).max()
depth_crop = depth_crop.astype(np.float32) / depth_scale # Has to be float32, 64 not supported.
with TimeIt('Inpainting'):
depth_crop = cv2.inpaint(depth_crop, depth_nan_mask, 1, cv2.INPAINT_NS)
# Back to original size and value range.
depth_crop = depth_crop[1:-1, 1:-1]
depth_crop = depth_crop * depth_scale
with TimeIt('5'):
# Resize
depth_crop = cv2.resize(depth_crop, (out_size, out_size), cv2.INTER_AREA)
if return_mask:
with TimeIt('6'):
depth_nan_mask = depth_nan_mask[1:-1, 1:-1]
depth_nan_mask = cv2.resize(depth_nan_mask, (out_size, out_size), cv2.INTER_NEAREST)
return depth_crop, depth_nan_mask
else:
return depth_crop
示例7: main
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def main():
image = cv2.imread("../data/5.1.11.tiff", 0)
cv2.imshow("Orignal Image", image)
# Laplacian High Pass Filter
lap_filter = cv2.Laplacian(image, ddepth=-1, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Laplacian Filter", lap_filter)
# Sobel High Pass Filter
sobelx_filter = cv2.Sobel(image, ddepth=-1, dx=2, dy=0, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Sobel X Filter", sobelx_filter)
sobely_filter = cv2.Sobel(image, ddepth=-1, dx=0, dy=2, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Sobel Y Filter", sobely_filter)
sobel_filter = sobelx_filter + sobely_filter
cv2.imshow("Sobel Filter", sobel_filter)
# Scharr High Pass Filter Implementation
scharrx_filter = cv2.Scharr(image, ddepth=-1, dx=1, dy=0, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Scharr X Filter", scharrx_filter)
scharry_filter = cv2.Scharr(image, ddepth=-1, dx=0, dy=1, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Scharr Y Filter", scharry_filter)
scharr_filter = scharrx_filter + scharry_filter
cv2.imshow("Scharr Filter", scharr_filter)
cv2.waitKey(0)
cv2.destroyAllWindows()
示例8: text_detect
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def text_detect(img,ele_size=(8,2)): #
if len(img.shape)==3:
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img_sobel = cv2.Sobel(img,cv2.CV_8U,1,0)#same as default,None,3,1,0,cv2.BORDER_DEFAULT)
img_threshold = cv2.threshold(img_sobel,0,255,cv2.THRESH_OTSU+cv2.THRESH_BINARY)
element = cv2.getStructuringElement(cv2.MORPH_RECT,ele_size)
img_threshold = cv2.morphologyEx(img_threshold[1],cv2.MORPH_CLOSE,element)
res = cv2.findContours(img_threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
if cv2.__version__.split(".")[0] == '3':
_, contours, hierarchy = res
else:
contours, hierarchy = res
Rect = [cv2.boundingRect(i) for i in contours if i.shape[0]>100]
RectP = [(int(i[0]-i[2]*0.08),int(i[1]-i[3]*0.08),int(i[0]+i[2]*1.1),int(i[1]+i[3]*1.1)) for i in Rect]
return RectP
示例9: test_box_filter_reflect_101
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def test_box_filter_reflect_101(self):
I = np.array(range(1, 50)).reshape(7, 7).astype(np.float32)
r = 2
ret1 = cv.smooth.box_filter(I, r, normalize=True)
ret2 = cv2.blur(I, (5,5), borderType=cv2.BORDER_DEFAULT)
self.assertTrue(np.array_equal(ret1, ret2))
示例10: process_depth_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_DEFAULT [as 别名]
def process_depth_image(depth, crop_size, out_size=300, return_mask=False, crop_y_offset=0):
imh, imw = depth.shape
with TimeIt('Process Depth Image'):
with TimeIt('Crop'):
# Crop.
depth_crop = depth[(imh - crop_size) // 2 - crop_y_offset:(imh - crop_size) // 2 + crop_size - crop_y_offset,
(imw - crop_size) // 2:(imw - crop_size) // 2 + crop_size]
# Inpaint
# OpenCV inpainting does weird things at the border.
with TimeIt('Inpainting_Processing'):
depth_crop = cv2.copyMakeBorder(depth_crop, 1, 1, 1, 1, cv2.BORDER_DEFAULT)
depth_nan_mask = np.isnan(depth_crop).astype(np.uint8)
kernel = np.ones((3, 3),np.uint8)
depth_nan_mask = cv2.dilate(depth_nan_mask, kernel, iterations=1)
depth_crop[depth_nan_mask==1] = 0
# Scale to keep as float, but has to be in bounds -1:1 to keep opencv happy.
depth_scale = np.abs(depth_crop).max()
depth_crop = depth_crop.astype(np.float32) / depth_scale # Has to be float32, 64 not supported.
with TimeIt('Inpainting'):
depth_crop = cv2.inpaint(depth_crop, depth_nan_mask, 1, cv2.INPAINT_NS)
# Back to original size and value range.
depth_crop = depth_crop[1:-1, 1:-1]
depth_crop = depth_crop * depth_scale
with TimeIt('Resizing'):
# Resize
depth_crop = cv2.resize(depth_crop, (out_size, out_size), cv2.INTER_AREA)
if return_mask:
with TimeIt('Return Mask'):
depth_nan_mask = depth_nan_mask[1:-1, 1:-1]
depth_nan_mask = cv2.resize(depth_nan_mask, (out_size, out_size), cv2.INTER_NEAREST)
return depth_crop, depth_nan_mask
else:
return depth_crop