Python cv2.BORDER_DEFAULT Examples
The following are 10
code examples of cv2.BORDER_DEFAULT().
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: plate_locate.py From EasyPR-python with Apache License 2.0 | 8 votes |
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
Example #2
Source File: image.py From ggcnn with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #3
Source File: datapreptools.py From DmsMsgRcg with Apache License 2.0 | 5 votes |
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))
Example #4
Source File: plate_locate.py From EasyPR-python with Apache License 2.0 | 5 votes |
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
Example #5
Source File: image.py From ggcnn with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #6
Source File: ggcnn_torch.py From mvp_grasp with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #7
Source File: HighPassFilter.py From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License | 5 votes |
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()
Example #8
Source File: TextDetect.py From text-detection with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #9
Source File: test_box_filter.py From guided-filter with MIT License | 5 votes |
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))
Example #10
Source File: ggcnn.py From mvp_grasp with BSD 3-Clause "New" or "Revised" License | 4 votes |
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