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
  • 相关阅读:
    fpga配置方式 .jic固化为ps模式
    fpga新建nios
    四轴飞行器飞行原理与双闭环PID控制
    fpga为什么要用nios 开发
    error A space is required after ',' comma-spacing
    vuex : Newline required at end of file but not found eol-last
    vue -Missing space before value for key 'path'vue.js解决空格报错
    visual studio 自动补全功能 以及代码没有颜色
    hadoop 伪分布模式环境搭建
    django框架-DRF工程之认证功能
  • 原文地址:https://www.cnblogs.com/CaiFengYuanXing/p/13781413.html
Copyright © 2011-2022 走看看