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
  • 相关阅读:
    浅谈ConcurrentHashMap实现原理
    HashMap底层实现原理及扩容机制
    浅谈fail-fast机制
    《从Lucene到Elasticsearch:全文检索实战》学习笔记五
    《从Lucene到Elasticsearch:全文检索实战》学习笔记四
    JVM垃圾回收算法解析
    《从Lucene到Elasticsearch:全文检索实战》学习笔记三
    《从Lucene到Elasticsearch:全文检索实战》学习笔记二
    python print()内置函数
    《从Lucene到Elasticsearch:全文检索实战》学习笔记一
  • 原文地址:https://www.cnblogs.com/CaiFengYuanXing/p/13781413.html
Copyright © 2011-2022 走看看