• 2色彩转化,高斯模糊


    1#色彩空间转化

    def color_space_demo(image):
    gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
    cv.imshow("gray", gray)
    hsv = cv.cvtColor(image, cv.COLOR_BGR2HSV)
    cv.imshow("hsv", hsv)
    yuv = cv.cvtColor(image, cv.COLOR_BGR2YUV)
    cv.imshow("yuv", yuv)
    Ycrcb = cv.cvtColor(image, cv.COLOR_BGR2YCrCb)
    cv.imshow("ycrcb", Ycrcb)

    2几种常见模糊

    #3模糊
    import cv2 as cv
    import numpy as np
    
    
    #均值模糊
    def blur_demo(image):
        dst = cv.blur(image, (5, 5))#参数1为水平方向模糊数值,参数2为竖直方向
        cv.imshow("blur_demo", dst)
    
    
    #中值模糊--可以用于去除椒盐去噪
    def median_blur_demo(image):
        dst = cv.medianBlur(image, 5)
        cv.imshow("median_blur_demo", dst)
    
    
    #自由定义
    def custom_blur_demo(image):
        #kernel = np.ones([5, 5], np.float32)/25
        kernel = np.array([[0, -1, 0],[-1, 5, -1],[0, -1, 0]], np.float32)
        dst = cv.filter2D(image, -1, kernel=kernel)
        cv.imshow("custom_blur_demo", dst)
    
    
    print("--------- Hello Python ---------")
    src = cv.imread("D:/vcprojects/images/demo.png")
    cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
    cv.imshow("input image", src)
    custom_blur_demo(src)
    cv.waitKey(0)
    
    cv.destroyAllWindows()

    3高斯模糊

    #高斯模糊--重要,有效,滤镜效果,语法:st = cv.GaussianBlur(src, (0, 0), 15)
    src = cv.imread("D:/vcprojects/images/example.png")
    cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
    cv.imshow("input image", src)
    
    t1 = cv.getTickCount()
    #gaussian_noise(src)
    t2 = cv.getTickCount()
    time = (t2 - t1)/cv.getTickFrequency()
    print("time consume : %s"%(time*1000))
    dst = cv.GaussianBlur(src, (0, 0), 15)
    cv.imshow("Gaussian Blur", dst)
    
    #高斯双边--美颜磨皮效果
    #均值迁移--羽化效果
    
    import cv2 as cv
    import numpy as np
    
    
    def bi_demo(image):#高斯双边
        dst = cv.bilateralFilter(image, 0, 100, 15)
        cv.imshow("bi_demo", dst)
    
    
    def shift_demo(image):#均值迁移
        dst = cv.pyrMeanShiftFiltering(image, 10, 50)
        cv.imshow("shift_demo", dst)
    
    
    print("--------- Hello Python ---------")
    src = cv.imread("C:/Users/wml/Desktop/wml/ym.jpg")
    cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
    cv.imshow("input image", src)
    # bi_demo(src)
    shift_demo(src)
    cv.waitKey(0)
    cv.destroyAllWindows()
    
    
  • 相关阅读:
    CentOS查看系统信息和资源使用已经升级系统的命令
    192M内存的VPS,安装Centos 6 minimal x86,无法安装node.js
    Linux限制资源使用的方法
    多域名绑定同一IP地址,Node.js来实现
    iOS 百度地图大头针使用
    iOS 从app跳转到Safari、从app打开电话呼叫
    设置cell背景色半透明
    AsyncSocket 使用
    iOS 监听键盘变化
    iOS 7 标签栏控制器进行模态视图跳转后变成透明
  • 原文地址:https://www.cnblogs.com/wml2018/p/12181662.html
Copyright © 2020-2023  润新知