zoukankan      html  css  js  c++  java
  • opencv简单卷积运用

    import  cv2 as cv

    import numpy as np

    img=cv.imread('learn.jpg',cv.IMREAD_GRAYSCALE)

    cv.imshow('first image',img)
    img_size=img.shape
    print(img_size)

    imgkernel=np.array([[-2,-1,0],
    [-1, 1,1],
    [ 0, 1,2]]
    )

    print(imgkernel)
    #利用CV的卷积核卷积图像

    dst=cv.filter2D(img,-1,imgkernel)
    cv.imshow('filter img',dst)
    print(dst.shape) #可以查看数组没变,说明为same方式卷积

    img_dst=np.hstack((img,dst))

    cv.imshow('merge img',img_dst)

    cv.waitKey()
    cv.destroyAllWindows()

    import  cv2 as cv

    import numpy as np
    img=cv.imread('learn.jpg',cv.IMREAD_GRAYSCALE)
    cv.imshow('first image',img)
    img_size=img.shape
    print(img_size)
    imgkernel=np.array([[-2,-1,0],
    [-1, 1,1],
    [ 0, 1,2]]
    )
    # print(imgkernel)
    #利用CV的卷积核卷积图像
    dst=cv.filter2D(img,-1,imgkernel)
    # cv.imshow('filter img',dst)
    # print(dst.shape) #可以查看数组没变,说明为same方式卷积
    img_dst=np.hstack((img,dst))
    cv.imshow('merge img',img_dst)
    img_cany=cv.Canny(img,100,200)
    # print(img_cany)
    # cv.imshow('canny image',img_cany)
    img_dst_canny=np.hstack((img_cany,img_cany))
    img_total=np.vstack(( img_dst,img_dst_canny))
    cv.imshow('all image',img_total)
    cv.waitKey()
    cv.destroyAllWindows()
    
    

    import  cv2 as cv
    import numpy as np
    img=cv.imread('learn.jpg',cv.IMREAD_GRAYSCALE)
    # cv.imshow('first image',img)
    # img_size=img.shape
    # print(img_size)
    imgkernel=np.array([[-2,-1,0],
    [-1, 1,1],
    [ 0, 1,2]]
    )
    # print(imgkernel)
    #利用CV的卷积核卷积图像
    dst=cv.filter2D(img,-1,imgkernel)
    # cv.imshow('filter img',dst)
    # print(dst.shape) #可以查看数组没变,说明为same方式卷积
    img_dst=np.hstack((img,dst))
    # cv.imshow('merge img',img_dst)
    img_cany=cv.Canny(img,100,200)
    # print(img_cany)
    # cv.imshow('canny image',img_cany)
    img_dst_canny=np.hstack((img_cany,img_cany))
    img_total=np.vstack(( img_dst,img_dst_canny))
    # cv.imshow('all image',img_total)
    ret,threshold=cv.threshold(img,100,200,0)
    print(ret)
    print(threshold)
    cv.imshow('threshold',threshold)
    img1=threshold-img
    ret1,threshold1=cv.threshold(img1,10,200,0)
    print(ret1)
    cv.imshow('threshold1',threshold1)
    cv.waitKey()
    cv.destroyAllWindows()







  • 相关阅读:
    致应届毕业生——程序员的生存法则 转自CSDN 作者:陈丽辉
    TIOBE 8月份编程语言排行榜,F#强势插入
    C–gcc命令行下的参数
    转载sunboy_2050 Android APK反编译详解(附图)
    转载IT168 分析:Python在Linux平台上的发展前景
    PHP 简单学习过程1
    买火车票必须知道的事
    Delphi PointerMath编译指令
    给DropDownList的DataTextField属性绑定两个字段
    通过HttpModule、httpHandlers防止SQL注入式攻击
  • 原文地址:https://www.cnblogs.com/tangjunjun/p/11243361.html
Copyright © 2011-2022 走看看