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
  • 相关阅读:
    Java基础学习——异常机制与集合的结合练习
    公司标签
    【JS语法糖】常见的几种JS语法糖
    webstorm批量替换
    webstorm 全局搜索快捷键_IntelliJ 的搜索和全局搜索怎么用
    存放缓存的三种方式 Redis、Memcache和MongoDB的区别
    Airtest学习(二)Airtest-Selenium 点击 断言 生成报告
    使用git克隆指定分支的代码
    nodejs v16.x 或更高版本不支持 Fibers
    使用 nvm 管理多个版本的 nodejs 和 npm,nvm的命令合集
  • 原文地址:https://www.cnblogs.com/CaiFengYuanXing/p/13781413.html
Copyright © 2011-2022 走看看