zoukankan      html  css  js  c++  java
  • 梯度

    xy轴梯度(sobel算子):

    import numpy as np
    import cv2 as cv
    import matplotlib as plt
    cap = cv.VideoCapture(0)
    kerne = np.ones((10, 10), np.uint8)
    while True:
        ret, frame = cap.read()
        sobel = cv.Sobel(frame, cv.CV_64F, 0, 1, 3)  # x,y 方向都有
        sobel_abs = cv.convertScaleAbs(sobel)  # 取绝对值操作
        add = np.hstack((frame, sobel_abs))
        cv.imshow('add', add)
        if cv.waitKey(1) == 27:
            break

    sobel算子

     [ -1, 0, 1

       -2, 0, 2

       -1, 0, 1 ]

    xy权重相加:

    import numpy as np
    import cv2 as cv
    import matplotlib as plt
    cap = cv.VideoCapture(0)
    kerne = np.ones((10, 10), np.uint8)
    while True:
    ret, frame = cap.read()
    sobelx = cv.Sobel(frame, cv.CV_64F, 0, 1, 3)
    sobelx = cv.convertScaleAbs(sobelx)
    sobely = cv.Sobel(frame, cv.CV_64F, 1, 0, 3)
    sobely = cv.convertScaleAbs(sobely)
    sobelxy = cv.addWeighted(sobelx, 0.5, sobely, 0.5, 0) # 取绝对值操作
    add = np.hstack((frame, sobelxy))
    cv.imshow('add', add)
    if cv.waitKey(1) == 27:
    break

     scharr算子和laplacian算子:

    import numpy as np
    import cv2 as cv
    import matplotlib as plt
    cap = cv.VideoCapture(0)
    kerne = np.ones((10, 10), np.uint8)
    while True:
        ret, frame = cap.read()
        sobelx = cv.Sobel(frame, cv.CV_64F, 0, 1, 3)
        sobelx = cv.convertScaleAbs(sobelx)
        sobely = cv.Sobel(frame, cv.CV_64F, 1, 0, 3)
        sobely = cv.convertScaleAbs(sobely)
        sobelxy = cv.addWeighted(sobelx, 0.5, sobely, 0.5, 0)  # 取绝对值操作
    
        scharrx = cv.Scharr(frame, cv.CV_64F, 0, 1, 3)
        scharrx = cv.convertScaleAbs(scharrx)
        scharry = cv.Scharr(frame, cv.CV_64F, 1, 0, 3)
        scharry = cv.convertScaleAbs(scharry)
        scharrxy = cv.addWeighted(sobelx, 0.5, sobely, 0.5, 0)  # 取绝对值操作
    
        laplacian = cv.Laplacian(frame, cv.CV_64F)
        laplacian = cv.convertScaleAbs(laplacian)
        add = np.hstack((frame, sobelxy, scharrxy, laplacian))
        cv.imshow('add', add)
        if cv.waitKey(1) == 27:
            break

     scharr算子

     [ -3,   0,  3               

       -10, 0,  10

       -3,   0,   3 ]   

    laplacian算子

     [ 0,   1,  0               

       1,  -4,  1

       0,   1,   0 ]   

    Canny边缘检测:

    import numpy as np
    import cv2 as cv
    import matplotlib as plt
    cap = cv.VideoCapture(0)
    kerne = np.ones((10, 10), np.uint8)
    while True:
        ret, frame = cap.read()
        canny = cv.Canny(frame, 80, 100)
    
        cv.imshow('add', canny)
        if cv.waitKey(1) == 27:
            break
  • 相关阅读:
    1202诗人基本介绍&诗人画像
    1205人物关系优化&诗人轨迹
    把SQL Server 2000 表中的自动编号Id重新开始排列
    一个一直都不明白的东西今天知道了。关于sqlserver2000自动执行。
    服装打版界的扛把子ET自定义操作
    手把手教你搭建集中式版本控制系统SVN服务器
    分享一次实用的爬虫经验
    盘点CSV文件在Excel中打开后乱码问题的两种处理方法
    盘点服装设计所经常性使用的软件ET(下篇)
    sql 每个企业选择一条产品
  • 原文地址:https://www.cnblogs.com/CaiFengYuanXing/p/13781413.html
Copyright © 2011-2022 走看看