当前位置: 首页>>代码示例>>Python>>正文


Python cv2.Laplacian方法代码示例

本文整理汇总了Python中cv2.Laplacian方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.Laplacian方法的具体用法?Python cv2.Laplacian怎么用?Python cv2.Laplacian使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


在下文中一共展示了cv2.Laplacian方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: laplacian

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def laplacian(filepathname):
    v = cv2.imread(filepathname)
    s = cv2.cvtColor(v, cv2.COLOR_BGR2GRAY)
    s = cv2.Laplacian(s, cv2.CV_16S, ksize=3)
    s = cv2.convertScaleAbs(s)
    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() 
开发者ID:cilame,项目名称:vrequest,代码行数:20,代码来源:pycv2.py

示例2: _lapulaseDetection

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def _lapulaseDetection(self, imgName):
        """
        :param strdir: 文件所在的目录
        :param name: 文件名称
        :return: 检测模糊后的分数
        """
        # step1: 预处理
        img2gray, reImg = self.preImgOps(imgName)
        # step2: laplacian算子 获取评分
        resLap = cv2.Laplacian(img2gray, cv2.CV_64F)
        score = resLap.var()
        print("Laplacian %s score of given image is %s", str(score))
        # strp3: 绘制图片并保存  不应该写在这里  抽象出来   这是共有的部分
        newImg = self._drawImgFonts(reImg, str(score))
        newDir = self.strDir + "/_lapulaseDetection_/"
        if not os.path.exists(newDir):
            os.makedirs(newDir)
        newPath = newDir + imgName
        # 显示
        cv2.imwrite(newPath, newImg)  # 保存图片
        cv2.imshow(imgName, newImg)
        cv2.waitKey(0)

        # step3: 返回分数
        return score 
开发者ID:Leezhen2014,项目名称:python--,代码行数:27,代码来源:BlurDetection.py

示例3: _find_edges_laplacian

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def _find_edges_laplacian(image, edge_multiplier, from_colorspace):
    image_gray = colorlib.change_colorspace_(np.copy(image),
                                             to_colorspace=colorlib.CSPACE_GRAY,
                                             from_colorspace=from_colorspace)
    image_gray = image_gray[..., 0]
    edges_f = cv2.Laplacian(_normalize_cv2_input_arr_(image_gray / 255.0),
                            cv2.CV_64F)
    edges_f = np.abs(edges_f)
    edges_f = edges_f ** 2
    vmax = np.percentile(edges_f, min(int(90 * (1/edge_multiplier)), 99))
    edges_f = np.clip(edges_f, 0.0, vmax) / vmax

    edges_uint8 = np.clip(np.round(edges_f * 255), 0, 255.0).astype(np.uint8)
    edges_uint8 = _blur_median(edges_uint8, 3)
    edges_uint8 = _threshold(edges_uint8, 50)
    return edges_uint8


# Added in 0.4.0. 
开发者ID:aleju,项目名称:imgaug,代码行数:21,代码来源:artistic.py

示例4: laplacian

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def laplacian(mask):
  '''
    Get 2nd order gradients using the Laplacian
  '''

  # blur
  mask = cv2.GaussianBlur(mask, (5, 5), 0)

  # edges with laplacian
  laplacian = cv2.Laplacian(mask, cv2.CV_64F, 5)

  # stretch
  laplacian = contrast_stretch(laplacian)

  # cast
  laplacian = np.uint8(laplacian)

  return laplacian 
开发者ID:PRBonn,项目名称:bonnet,代码行数:20,代码来源:plant_features.py

示例5: preprocess_filt_lap

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def preprocess_filt_lap(self):
        '''
        Do the pre processing using Laplacian filter (2.5 min / 4 min).
        '''
        import cv2
        import numpy as np
        
        
        if self.zeroMask is not None:
            self.zeroMask = (self.I1 == 0)

        self.I1 = 20.0 * np.log10(self.I1)
        self.I1 = cv2.Laplacian(self.I1,-1,ksize=self.WallisFilterWidth,borderType=cv2.BORDER_CONSTANT)

        self.I2 = 20.0 * np.log10(self.I2)
        self.I2 = cv2.Laplacian(self.I2,-1,ksize=self.WallisFilterWidth,borderType=cv2.BORDER_CONSTANT) 
开发者ID:leiyangleon,项目名称:autoRIFT,代码行数:18,代码来源:autoRIFT.py

示例6: get_laplace_points

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def get_laplace_points(self, image: np.ndarray, num_points=500) -> np.ndarray:
        if num_points <= 0:
            return np.zeros((0, 2), dtype=np.uint8)
        image = cv2.GaussianBlur(image, (15, 15), 0)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        image = np.uint8(np.absolute(cv2.Laplacian(image, cv2.CV_64F, 19)))
        image = cv2.GaussianBlur(image, (15, 15), 0)
        image = (image * (255 / image.max())).astype(np.uint8)
        image = image.astype(np.float32) / image.sum()
        if self.options['visualize_laplace']:
            self.visualize_image(image, 'laplace')
        weights = np.ravel(image)
        coordinates = np.arange(0, weights.size, dtype=np.uint32)
        choices = np.random.choice(coordinates, size=num_points, replace=False, p=weights)
        raw_points = np.unravel_index(choices, image.shape)
        points = np.stack(raw_points, axis=-1)[..., ::-1]
        return points 
开发者ID:tasercake,项目名称:lowpolypy,代码行数:19,代码来源:process.py

示例7: get_best_images

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def get_best_images(plate_images, num_img_return):
    """
    Get the top num_img_return quality images (with the least blur).
    Laplacian function returns a value which indicates how blur the image is.
    The lower the value, the more blur the image have
    """

    # first, pick the image with the largest area because the bigger the image, the bigger the characters on the plate
    if len(plate_images) > (num_img_return + 2):
        plate_images = sorted(plate_images, key=lambda x : x[0].shape[0]*x[0].shape[1], reverse=True)[:(num_img_return+2)]

    # secondly, pick the images with the least blur
    if len(plate_images) > num_img_return:
        plate_images = sorted(plate_images, key=lambda img : cv2.Laplacian(img[0], cv2.CV_64F).var(), reverse=True)[:num_img_return]
        # img[0] because plate_images = [plate image, char on plate]
    return plate_images 
开发者ID:longphungtuan94,项目名称:ALPR_System,代码行数:18,代码来源:find_best_quality_images.py

示例8: variance_of_laplacian

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def variance_of_laplacian(image):
	# compute the Laplacian of the image and then return the focus
	# measure, which is simply the variance of the Laplacian
	return cv2.Laplacian(image, cv2.CV_64F).var()



# In[ ]:



# In[ ]:


#accuracy_score(y, y_pred)


# In[4]: 
开发者ID:priyabagaria,项目名称:Image-Blur-Detection,代码行数:20,代码来源:OpenCV_var.py

示例9: sketch_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def sketch_image(img):
    """Sketches the image applying a laplacian operator to detect the edges"""

    # Convert to gray scale
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Apply median filter
    img_gray = cv2.medianBlur(img_gray, 5)

    # Detect edges using cv2.Laplacian()
    edges = cv2.Laplacian(img_gray, cv2.CV_8U, ksize=5)

    # Threshold the edges image:
    ret, thresholded = cv2.threshold(edges, 70, 255, cv2.THRESH_BINARY_INV)

    return thresholded 
开发者ID:PacktPublishing,项目名称:Mastering-OpenCV-4-with-Python,代码行数:18,代码来源:cartoonizing.py

示例10: worker

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def worker(path, select_folder, waste_img_folder, crop_sz, stride, thres_sz, cont_var_thresh, freq_var_thresh):
    img_name = os.path.basename(path)
    img = cv2.imread(path, cv2.IMREAD_UNCHANGED)
    h, w, c = img.shape

    h_space = np.arange(0, h - crop_sz + 1, stride)
    if h - (h_space[-1] + crop_sz) > thres_sz:
        h_space = np.append(h_space, h - crop_sz)
    w_space = np.arange(0, w - crop_sz + 1, stride)
    if w - (w_space[-1] + crop_sz) > thres_sz:
        w_space = np.append(w_space, w - crop_sz)

    index = 0
    for x in h_space:
        for y in w_space:
            index += 1
            patch_name = img_name.replace('.png', '_s{:05d}.png'.format(index))
            patch = img[x:x + crop_sz, y:y + crop_sz, :]

            im_gray = patch[:, :, 1]

            [mean, var] = cv2.meanStdDev(im_gray)
            freq_var = cv2.Laplacian(im_gray, cv2.CV_8U).var()

            if var > cont_var_thresh and freq_var>freq_var_thresh:
                cv2.imwrite(os.path.join(select_folder, patch_name), patch)
            else:
                cv2.imwrite(os.path.join(waste_img_folder, patch_name), patch)
    return 'Processing {:s} ...'.format(img_name) 
开发者ID:guochengqian,项目名称:TENet,代码行数:31,代码来源:crop_imgs.py

示例11: LaplacianOfGaussian

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def LaplacianOfGaussian(image):
    LoG_image = cv2.GaussianBlur(image, (3,3), 0)           # paramter 
    gray = cv2.cvtColor( LoG_image, cv2.COLOR_BGR2GRAY)
    LoG_image = cv2.Laplacian( gray, cv2.CV_8U,3,3,2)       # parameter
    LoG_image = cv2.convertScaleAbs(LoG_image)
    return LoG_image 
开发者ID:hoanglehaithanh,项目名称:Traffic-Sign-Detection,代码行数:8,代码来源:main.py

示例12: extract_sub_features

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def extract_sub_features(self, img, debug=False):
        laplacian_threshold = 192
        img_subavg = sub_average(img)
        img_gray = cv2.cvtColor(img_subavg, cv2.COLOR_BGR2GRAY)
        img_gray_laplacian = cv2.Laplacian(img_gray, cv2.CV_64F)
        img_laplacian_abs = cv2.convertScaleAbs(img_gray_laplacian)
        a, img_laplacian_abs_thres = cv2.threshold(
            img_laplacian_abs, laplacian_threshold, 255, 0)

        img_gray_custom = get_img_custom(None, img_gray)
        img_gray_custom = max_pooling_2d(None, img_gray, (4, 4))
        return np.array(img_gray_custom, dtype=np.float32)

    # Define weapon classification specific features. 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:16,代码来源:weapon.py

示例13: down_sample_2d

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def down_sample_2d(self, src, w, h):
        sy, sx = src.shape[0:2]

        out_img = np.zeros((h, w), np.uint8)
        for x in range(w):
            for y in range(h):
                x1 = int((x / w) * sx)
                y1 = int((y / h) * sy)
                x2 = int(((x + 1) / w) * sx)
                y2 = int(((y + 1) / h) * sy)
                out_img[y, x] = np.amax(src[y1:y2, x1:x2])

        max_value = np.amax(out_img)
        if max_value > 0:
            out_img = ((out_img * 1.0) / max_value)

        if 0:
            cv2.imshow('orig', cv2.resize(src, (128, 128),
                                          interpolation=cv2.INTER_NEAREST))
            cv2.imshow('resize', cv2.resize(
                out_img, (128, 128), interpolation=cv2.INTER_NEAREST))
            cv2.waitKey(10)

        return out_img

    # Normalize the image.
    #
    # - Crop the image
    # - Apply Laplacian edge detector
    # - Convert to grayscale
    # - Threshold the image
    # - Down-sample to 12x12
    #
    # @param img    the source image
    # @return (img,out_img)  the result 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:37,代码来源:icon.py

示例14: normalize_icon_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def normalize_icon_image(self, img):
        h, w = img.shape[0:2]

        laplacian_threshold = 60
        img_laplacian = cv2.Laplacian(img, cv2.CV_64F)
        img_laplacian_abs = cv2.convertScaleAbs(img_laplacian)
        img_laplacian_gray = \
            cv2.cvtColor(img_laplacian_abs, cv2.COLOR_BGR2GRAY)
        ret, img_laplacian_mask = \
            cv2.threshold(img_laplacian_gray, laplacian_threshold, 255, 0)
        out_img = self.down_sample_2d(img_laplacian_mask, 12, 12)

        if False:
            cv2.imshow('orig', cv2.resize(img, (160, 160)))
            cv2.imshow('laplacian_abs', cv2.resize(
                img_laplacian_abs, (160, 160)))
            cv2.imshow('laplacian_gray', cv2.resize(
                img_laplacian_gray, (160, 160)))
            cv2.imshow('out', cv2.resize(out_img, (160, 160)))
            cv2.moveWindow('orig', 80, 20)
            cv2.moveWindow('laplacian_abs', 80, 220)
            cv2.moveWindow('laplacian_gray', 80, 420)
            cv2.moveWindow('out', 80, 820)
            ch = 0xFF & cv2.waitKey(1)
            if ch == ord('q'):
                sys.exit()
        return [
            out_img,
            img,
            img,  # ununsed
        ]

    # Define feature extraction algorithm. 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:35,代码来源:icon.py

示例15: cartoonize_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Laplacian [as 别名]
def cartoonize_image(img, ksize=5, sketch_mode=False):
    num_repetitions, sigma_color, sigma_space, ds_factor = 10, 5, 7, 4 
    # Convert image to grayscale 
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 
 
    # Apply median filter to the grayscale image 
    img_gray = cv2.medianBlur(img_gray, 7) 
 
    # Detect edges in the image and threshold it 
    edges = cv2.Laplacian(img_gray, cv2.CV_8U, ksize=ksize) 
    ret, mask = cv2.threshold(edges, 100, 255, cv2.THRESH_BINARY_INV) 
 
    # 'mask' is the sketch of the image 
    if sketch_mode: 
        return cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR) 
 
    # Resize the image to a smaller size for faster computation 
    img_small = cv2.resize(img, None, fx=1.0/ds_factor, fy=1.0/ds_factor, interpolation=cv2.INTER_AREA)
 
    # Apply bilateral filter the image multiple times 
    for i in range(num_repetitions): 
        img_small = cv2.bilateralFilter(img_small, ksize, sigma_color, sigma_space) 
 
    img_output = cv2.resize(img_small, None, fx=ds_factor, fy=ds_factor, interpolation=cv2.INTER_LINEAR) 
 
    dst = np.zeros(img_gray.shape) 
 
    # Add the thick boundary lines to the image using 'AND' operator 
    dst = cv2.bitwise_and(img_output, img_output, mask=mask) 
    return dst 
开发者ID:PacktPublishing,项目名称:OpenCV-3-x-with-Python-By-Example,代码行数:32,代码来源:05_cartoonizing.py


注:本文中的cv2.Laplacian方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。