Python cv2.blur() Examples
The following are 30
code examples of cv2.blur().
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: picam.py From PiCamNN with MIT License | 7 votes |
def movement(mat_1,mat_2): mat_1_gray = cv2.cvtColor(mat_1.copy(),cv2.COLOR_BGR2GRAY) mat_1_gray = cv2.blur(mat_1_gray,(blur1,blur1)) _,mat_1_gray = cv2.threshold(mat_1_gray,100,255,0) mat_2_gray = cv2.cvtColor(mat_2.copy(),cv2.COLOR_BGR2GRAY) mat_2_gray = cv2.blur(mat_2_gray,(blur1,blur1)) _,mat_2_gray = cv2.threshold(mat_2_gray,100,255,0) mat_2_gray = cv2.bitwise_xor(mat_1_gray,mat_2_gray) mat_2_gray = cv2.blur(mat_2_gray,(blur2,blur2)) _,mat_2_gray = cv2.threshold(mat_2_gray,70,255,0) mat_2_gray = cv2.erode(mat_2_gray,np.ones((erodeval,erodeval))) mat_2_gray = cv2.dilate(mat_2_gray,np.ones((4,4))) _, contours,__ = cv2.findContours(mat_2_gray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) if len(contours) > 0:return True #If there were any movements return False #if not #Pedestrian Recognition Thread
Example #2
Source File: faces_detect.py From faceswap with GNU General Public License v3.0 | 6 votes |
def set_blur_and_threshold(self, blur_kernel=0, blur_type="gaussian", blur_passes=1, threshold=0): """ Set the internal blur kernel and threshold amount for returned masks Parameters ---------- blur_kernel: int, optional The kernel size, in pixels to apply gaussian blurring to the mask. Set to 0 for no blurring. Should be odd, if an even number is passed in (outside of 0) then it is rounded up to the next odd number. Default: 0 blur_type: ["gaussian", "normalized"], optional The blur type to use. ``gaussian`` or ``normalized`` box filter. Default: ``gaussian`` blur_passes: int, optional The number of passed to perform when blurring. Default: 1 threshold: int, optional The threshold amount to minimize/maximize mask values to 0 and 100. Percentage value. Default: 0 """ logger.trace("blur_kernel: %s, threshold: %s", blur_kernel, threshold) if blur_type is not None: blur_kernel += 0 if blur_kernel == 0 or blur_kernel % 2 == 1 else 1 self._blur["kernel"] = blur_kernel self._blur["type"] = blur_type self._blur["passes"] = blur_passes self._threshold = (threshold / 100.0) * 255.0
Example #3
Source File: ChickenVision.py From ChickenVision with MIT License | 6 votes |
def threshold_video(lower_color, upper_color, blur): # Convert BGR to HSV hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV) # hold the HSV image to get only red colors mask = cv2.inRange(hsv, lower_color, upper_color) # Returns the masked imageBlurs video to smooth out image return mask # Finds the tape targets from the masked image and displays them on original stream + network tales
Example #4
Source File: .demo.py From dual-fisheye-video-stitching with MIT License | 6 votes |
def pivot_smooth(img, shape, wd, flags): pivot_m1 = img[:, 1280 - wd:1279 + wd, :] pivot_l = img[:, :wd, :] pivot_r = img[:, 2560 - wd:, :] pivot_m2 = np.append(pivot_r, pivot_l, axis=1) if flags: pivot_m1 = cv2.GaussianBlur(pivot_m1, shape, 0) pivot_m2 = cv2.GaussianBlur(pivot_m2, shape, 0) else: pivot_m1 = cv2.blur(pivot_m1, shape) pivot_m2 = cv2.blur(pivot_m2, shape) result = np.copy(img) result[:, 1280 - wd:1279 + wd, :] = pivot_m1 result[:, :wd, :] = pivot_m2[:, wd:, :] result[:, 2560 - wd:, :] = pivot_m2[:, :wd, :] return result
Example #5
Source File: pycv2.py From vrequest with MIT License | 6 votes |
def sobel(filepathname): v = cv2.imread(filepathname) s = cv2.cvtColor(v,cv2.COLOR_BGR2GRAY) x, y = cv2.Sobel(s,cv2.CV_16S,1,0), cv2.Sobel(s,cv2.CV_16S,0,1) s = cv2.convertScaleAbs(cv2.subtract(x,y)) s = cv2.blur(s,(9,9)) cv2.imshow('nier',s) return s # ret, binary = cv2.threshold(s,40,255,cv2.THRESH_BINARY) # contours, hierarchy = cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) # for c in contours: # x,y,w,h = cv2.boundingRect(c) # if w>5 and h>10: # cv2.rectangle(v,(x,y),(x+w,y+h),(155,155,0),1) # cv2.imshow('nier2',v) # cv2.waitKey() # cv2.destroyAllWindows()
Example #6
Source File: blur.py From imgaug with MIT License | 6 votes |
def __init__(self, sigma=(0.0, 3.0), seed=None, name=None, random_state="deprecated", deterministic="deprecated"): super(GaussianBlur, self).__init__( seed=seed, name=name, random_state=random_state, deterministic=deterministic) self.sigma = iap.handle_continuous_param( sigma, "sigma", value_range=(0, None), tuple_to_uniform=True, list_to_choice=True) # epsilon value to estimate whether sigma is sufficently above 0 to # apply the blur self.eps = 1e-3 # Added in 0.4.0.
Example #7
Source File: helpers.py From songoku with MIT License | 6 votes |
def blend_non_transparent(face_img, overlay_img): # Let's find a mask covering all the non-black (foreground) pixels # NB: We need to do this on grayscale version of the image gray_overlay = cv2.cvtColor(overlay_img, cv2.COLOR_BGR2GRAY) overlay_mask = cv2.threshold(gray_overlay, 1, 255, cv2.THRESH_BINARY)[1] # Let's shrink and blur it a little to make the transitions smoother... overlay_mask = cv2.erode(overlay_mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))) overlay_mask = cv2.blur(overlay_mask, (3, 3)) # And the inverse mask, that covers all the black (background) pixels background_mask = 255 - overlay_mask # Turn the masks into three channel, so we can use them as weights overlay_mask = cv2.cvtColor(overlay_mask, cv2.COLOR_GRAY2BGR) background_mask = cv2.cvtColor(background_mask, cv2.COLOR_GRAY2BGR) # Create a masked out face image, and masked out overlay # We convert the images to floating point in range 0.0 - 1.0 face_part = (face_img * (1 / 255.0)) * (background_mask * (1 / 255.0)) overlay_part = (overlay_img * (1 / 255.0)) * (overlay_mask * (1 / 255.0)) # And finally just add them together, and rescale it back to an 8bit integer image return np.uint8(cv2.addWeighted(face_part, 255.0, overlay_part, 255.0, 0.0))
Example #8
Source File: helpers.py From hazymaze with Apache License 2.0 | 6 votes |
def blend_non_transparent(sprite, background_img): gray_overlay = cv2.cvtColor(background_img, cv2.COLOR_BGR2GRAY) overlay_mask = cv2.threshold(gray_overlay, 1, 255, cv2.THRESH_BINARY)[1] overlay_mask = cv2.erode(overlay_mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))) overlay_mask = cv2.blur(overlay_mask, (3, 3)) background_mask = 255 - overlay_mask overlay_mask = cv2.cvtColor(overlay_mask, cv2.COLOR_GRAY2BGR) background_mask = cv2.cvtColor(background_mask, cv2.COLOR_GRAY2BGR) sprite_part = (sprite * (1 / 255.0)) * (background_mask * (1 / 255.0)) overlay_part = (background_img * (1 / 255.0)) * (overlay_mask * (1 / 255.0)) return np.uint8(cv2.addWeighted(sprite_part, 255.0, overlay_part, 255.0, 0.0))
Example #9
Source File: imutil.py From python-utils with MIT License | 6 votes |
def downsample(img, scale=None, output_wh=None, max_side=None, min_side=None, block_size=None, mode=None): if max_side is not None: cur_max_side = max(img.shape[:2]) scale = max_side / cur_max_side if min_side is not None: cur_min_side = min(img.shape[:2]) scale = min_side / cur_min_side if scale is not None: output_wh = (int(np.round(img.shape[1]*scale)), int(np.round(img.shape[0]*scale))) if block_size is not None: output_wh = (img.shape[1]//block_size, img.shape[0]//block_size) else: block_size = img.shape[1]//output_wh[0] if block_size > 1: img = cv2.blur(img, (block_size, block_size)) return cv2.resize(img, output_wh, interpolation=cv2.INTER_AREA if mode is None else mode)
Example #10
Source File: 生成数据并增强.py From Semantic-segmentation-of-remote-sensing-images with Apache License 2.0 | 6 votes |
def data_augment(xb,yb): if np.random.random() < 0.25: xb,yb = rotate(xb,yb,90) if np.random.random() < 0.25: xb,yb = rotate(xb,yb,180) if np.random.random() < 0.25: xb,yb = rotate(xb,yb,270) if np.random.random() < 0.25: xb = cv2.flip(xb, 1) # flipcode > 0:沿y轴翻转 yb = cv2.flip(yb, 1) #对原图像做模糊处理 if np.random.random() < 0.25: xb = random_gamma_transform(xb,1.0) if np.random.random() < 0.25: xb = blur(xb) if np.random.random() < 0.2: xb = add_noise(xb) return xb,yb #创建数据
Example #11
Source File: infer.py From DewarpNet with MIT License | 6 votes |
def unwarp(img, bm): w,h=img.shape[0],img.shape[1] bm = bm.transpose(1, 2).transpose(2, 3).detach().cpu().numpy()[0,:,:,:] bm0=cv2.blur(bm[:,:,0],(3,3)) bm1=cv2.blur(bm[:,:,1],(3,3)) bm0=cv2.resize(bm0,(h,w)) bm1=cv2.resize(bm1,(h,w)) bm=np.stack([bm0,bm1],axis=-1) bm=np.expand_dims(bm,0) bm=torch.from_numpy(bm).double() img = img.astype(float) / 255.0 img = img.transpose((2, 0, 1)) img = np.expand_dims(img, 0) img = torch.from_numpy(img).double() res = F.grid_sample(input=img, grid=bm) res = res[0].numpy().transpose((1, 2, 0)) return res
Example #12
Source File: barcodeD&D_zbar.py From Barcode-Detection-and-Decoding with Apache License 2.0 | 6 votes |
def preprocess(image): # load the image image = cv2.imread(args["image"]) #resize image image = cv2.resize(image,None,fx=0.7, fy=0.7, interpolation = cv2.INTER_CUBIC) #convert to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) #calculate x & y gradient gradX = cv2.Sobel(gray, ddepth = cv2.CV_32F, dx = 1, dy = 0, ksize = -1) gradY = cv2.Sobel(gray, ddepth = cv2.CV_32F, dx = 0, dy = 1, ksize = -1) # subtract the y-gradient from the x-gradient gradient = cv2.subtract(gradX, gradY) gradient = cv2.convertScaleAbs(gradient) # blur the image blurred = cv2.blur(gradient, (3, 3)) # threshold the image (_, thresh) = cv2.threshold(blurred, 225, 255, cv2.THRESH_BINARY) thresh = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) return thresh
Example #13
Source File: blur.py From DL.EyeSight with GNU General Public License v3.0 | 6 votes |
def _augment_images(self, images, random_state, parents, hooks): result = images nb_images = len(images) if self.mode == "single": samples = self.k.draw_samples((nb_images,), random_state=random_state) samples = (samples, samples) else: samples = ( self.k[0].draw_samples((nb_images,), random_state=random_state), self.k[1].draw_samples((nb_images,), random_state=random_state), ) for i in range(nb_images): kh, kw = samples[0][i], samples[1][i] #print(images.shape, result.shape, result[i].shape) kernel_impossible = (kh == 0 or kw == 0) kernel_does_nothing = (kh == 1 and kw == 1) if not kernel_impossible and not kernel_does_nothing: image_aug = cv2.blur(result[i], (kh, kw)) # cv2.blur() removes channel axis for single-channel images if image_aug.ndim == 2: image_aug = image_aug[..., np.newaxis] result[i] = image_aug return result
Example #14
Source File: saliency.py From OpenCV-Computer-Vision-Projects-with-Python with MIT License | 6 votes |
def __init__(self, img, use_numpy_fft=True, gauss_kernel=(5, 5)): """Constructor This method initializes the saliency algorithm. :param img: an RGB input image :param use_numpy_fft: flag whether to use NumPy's FFT (True) or OpenCV's FFT (False) :param gauss_kernel: Kernel size for Gaussian blur """ self.use_numpy_fft = use_numpy_fft self.gauss_kernel = gauss_kernel self.frame_orig = img # downsample image for processing self.small_shape = (64, 64) self.frame_small = cv2.resize(img, self.small_shape[1::-1]) # whether we need to do the math (True) or it has already # been done (False) self.need_saliency_map = True
Example #15
Source File: morpher.py From yry with Apache License 2.0 | 6 votes |
def merge_img(src_img, dst_img, dst_matrix, dst_points, blur_detail_x=None, blur_detail_y=None, mat_multiple=None): face_mask = np.zeros(src_img.shape, dtype=src_img.dtype) for group in core.OVERLAY_POINTS: cv2.fillConvexPoly(face_mask, cv2.convexHull(dst_matrix[group]), (255, 255, 255)) r = cv2.boundingRect(np.float32([dst_points[:core.FACE_END]])) center = (r[0] + int(r[2] / 2), r[1] + int(r[3] / 2)) if mat_multiple: mat = cv2.getRotationMatrix2D(center, 0, mat_multiple) face_mask = cv2.warpAffine(face_mask, mat, (face_mask.shape[1], face_mask.shape[0])) if blur_detail_x and blur_detail_y: face_mask = cv2.blur(face_mask, (blur_detail_x, blur_detail_y), center) return cv2.seamlessClone(np.uint8(dst_img), src_img, face_mask, center, cv2.NORMAL_CLONE)
Example #16
Source File: Back_sub.py From virtual-dressing-room with Apache License 2.0 | 5 votes |
def loadBackground(self): self.__back__=cv2.imread("./train/back_g.jpg",cv2.cv.CV_LOAD_IMAGE_UNCHANGED) self.__back__=cv2.blur(self.__back__, (3,3))
Example #17
Source File: functional.py From dsb2018_topcoders with MIT License | 5 votes |
def random_polosa(img): gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) if np.mean(gray) < 100: empty = np.zeros(img.shape[:2], dtype=np.uint8) xs, ys = np.random.randint(0, empty.shape[1]), np.random.randint(0, empty.shape[0]) xe, ye = np.random.randint(0, empty.shape[1]), np.random.randint(0, empty.shape[0]) factor = np.random.randint(1, 10) / 3. cv2.line(empty, (xs, ys), (xe, ye), np.max(gray) / factor, thickness=np.random.randint(10, 100)) empty = cv2.blur(empty, (5, 5)) empty = empty | gray return cv2.cvtColor(empty, cv2.COLOR_GRAY2RGB) return img
Example #18
Source File: functional.py From dsb2018_topcoders with MIT License | 5 votes |
def blur(img, ksize): return cv2.blur(img, (ksize, ksize))
Example #19
Source File: functional.py From dsb2018_topcoders with MIT License | 5 votes |
def random_polosa(img): gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) if np.mean(gray) < 100: empty = np.zeros(img.shape[:2], dtype=np.uint8) xs, ys = np.random.randint(0, empty.shape[1]), np.random.randint(0, empty.shape[0]) xe, ye = np.random.randint(0, empty.shape[1]), np.random.randint(0, empty.shape[0]) factor = np.random.randint(1, 10) / 3. cv2.line(empty, (xs, ys), (xe, ye), np.max(gray) / factor, thickness=np.random.randint(10, 100)) empty = cv2.blur(empty, (5, 5)) empty = empty | gray return cv2.cvtColor(empty, cv2.COLOR_GRAY2RGB) return img
Example #20
Source File: abstract_dataset.py From bonnet with GNU General Public License v3.0 | 5 votes |
def augment(self, img, lbl): # define the augmentations # flip horizontally? flip = bool(random.getrandbits(1)) if flip: img = cv2.flip(img, 1) lbl = cv2.flip(lbl, 1) # gamma shift gamma = bool(random.getrandbits(1)) if gamma: # build a lookup table mapping the pixel values [0, 255] to # their adjusted gamma values randomGamma = np.random.uniform(low=0.8, high=1.2) invGamma = 1.0 / randomGamma table = np.array([((i / 255.0) ** invGamma) * 255 for i in np.arange(0, 256)]).astype("uint8") img = cv2.LUT(img, table) # blur blur = bool(random.getrandbits(1)) if blur: ksize = random.randint(3, 7) img = cv2.blur(img,(ksize,ksize)) return img, lbl
Example #21
Source File: en4242.py From facial_expressions with Apache License 2.0 | 5 votes |
def gauss_img(image, emotion, size = 5, in_folder = img_directory): img = cv2.imread(in_folder + image, 0) blur = cv2.GaussianBlur(img,(size,size), 0) save_image(blur, 'gauss' + image, emotion) # Applys a bilateral filter that sharpens the edges while bluring the other areas.
Example #22
Source File: en4242.py From facial_expressions with Apache License 2.0 | 5 votes |
def blur_img(image, emotion, size = 5, in_folder = img_directory): img = cv2.imread(in_folder + image, 0) blur = cv2.blur(img,(size,size)) save_image(blur, 'blur' + image, emotion) # Blurs the image using Gaussian weights from the 5X5 pixle square surrounding # each pixel.
Example #23
Source File: test_blur.py From imgaug with MIT License | 5 votes |
def test_kernel_size_0(self): # no blur, shouldnt change anything aug = iaa.AverageBlur(k=0) observed = aug.augment_image(self.base_img) assert np.array_equal(observed, self.base_img)
Example #24
Source File: blur.py From DeepPrivacy with MIT License | 5 votes |
def anonymize_face(self, face): if self.blur_type == "heavy_blur": ksize = int(0.3 * face.shape[1]) ksize = max(1, ksize) face = cv2.blur(face, (ksize, ksize)) return face elif self.blur_type == "gaussian_blur": face = cv2.GaussianBlur(face, (9, 9), sigmaX=3, sigmaY=3) return face else: raise AttributeError(f'Undefined blur type: {self.blur_type}')
Example #25
Source File: Back_sub.py From virtual-dressing-room with Apache License 2.0 | 5 votes |
def subtract_back(self,frm): #dst=self.__back__-self.__foreground__ temp=np.zeros((config.height,config.width),np.uint8) self.__foreground__=cv2.blur(self.__foreground__,(3,3)) dst=cv2.absdiff(self.__back__,self.__foreground__) #dst=cv2.adaptiveThreshold(dst,255,cv.CV_THRESH_BINARY,cv.CV_ADAPTIVE_THRESH_GAUSSIAN_C,5,10) val,dst=cv2.threshold(dst,0,255,cv.CV_THRESH_BINARY+cv.CV_THRESH_OTSU) fg=cv2.erode(dst,None,iterations=1) bg=cv2.dilate(dst,None,iterations=4) _,bg=cv2.threshold(bg,1,128,1) mark=cv2.add(fg,bg) mark32=np.int32(mark) #dst.copy(temp) #seq=cv.FindContours(cv.fromarray(dst),self.mem,cv.CV_RETR_EXTERNAL,cv.CV_CHAIN_APPROX_SIMPLE) #cntr,h=cv2.findContours(dst,cv.CV_RETR_EXTERNAL,cv.CV_CHAIN_APPROX_SIMPLE) #print cntr,h #cv.DrawContours(cv.fromarray(temp),seq,(255,255,255),(255,255,255),1,cv.CV_FILLED) cv2.watershed(frm, mark32) self.final_mask=cv2.convertScaleAbs(mark32) #print temp #--outputs--- #cv2.imshow("subtraction",fg) #cv2.imshow("thres",dst) #cv2.imshow("thres1",bg) #cv2.imshow("mark",mark) #cv2.imshow("final",self.final_mask)
Example #26
Source File: cv_bridge_demo.py From Learning-Robotics-using-Python-Second-Edition with MIT License | 5 votes |
def process_image(self, frame): # Convert to greyscale grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Blur the image grey = cv2.blur(grey, (7, 7)) # Compute edges using the Canny edge filter edges = cv2.Canny(grey, 15.0, 30.0) return edges
Example #27
Source File: image.py From BirdCLEF-Baseline with MIT License | 5 votes |
def blur(img, kernel_size=3): return cv2.blur(img, (kernel_size, kernel_size))
Example #28
Source File: ImageTransform.py From DRFNS with MIT License | 5 votes |
def _apply_(self, *image): res = () n_img = 0 for img in image: if n_img == 1: sub_res = self.OutputType(img) else: sigma = self.params["sigma"] sub_res = cv2.blur(img, (sigma, sigma)) sub_res = self.OutputType(sub_res) n_img += 1 res += (sub_res,) return res
Example #29
Source File: cv_bridge_demo.py From Learning-Robotics-using-Python-Second-Edition with MIT License | 5 votes |
def process_image(self, frame): # Convert to greyscale grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Blur the image grey = cv2.blur(grey, (7, 7)) # Compute edges using the Canny edge filter edges = cv2.Canny(grey, 15.0, 30.0) return edges
Example #30
Source File: augmentor.py From lffd-pytorch with MIT License | 5 votes |
def blur(image, mode='random', kernel_size=3, sigma=1): """ :param image: :param mode: options 'normalized' 'gaussian' 'median' :param kernel_size: :param sigma: used for gaussian blur :return: """ if image.dtype != numpy.uint8: print('Input image is not uint8!') return None if mode == 'random': mode = random.choice(['normalized', 'gaussian', 'median']) if mode == 'normalized': result = cv2.blur(image, (kernel_size, kernel_size)) elif mode == 'gaussian': result = cv2.GaussianBlur(image, (kernel_size, kernel_size), sigmaX=sigma, sigmaY=sigma) elif mode == 'median': result = cv2.medianBlur(image, kernel_size) else: print('Blur mode is not supported: %s.' % mode) result = image return result