opencv_day5

import cv2
import matplotlib.pylab as plt
import numpy as np
img1 = cv2.imread('D:\\gudugudu\\Pictures\\weixin\\xiaotidaya.jpg', cv2.IMREAD_ANYCOLOR)
img2 = cv2.imread('D:\\gudugudu\\Pictures\\weixin\\guoqing.jpg', cv2.IMREAD_GRAYSCALE)
img3 = cv2.imread('D:\\gudugudu\\Pictures\\weixin\\zhaoyang.jpg', cv2.IMREAD_GRAYSCALE)
img_x = cv2.resize(img1, (500, 500))
img_y = cv2.resize(img2, (500, 500))
img_z = cv2.resize(img3, (500, 500))
vc = cv2.VideoCapture("D:\\gudugudu\\Pictures\\weixin\\WeChat_20240706150425.mp4")


def cv_show(name, img):
    cv2.imshow('name', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


def erode(img): #图像腐蚀操作
    kernel = np.ones((5, 5), np.uint8)  #选择腐蚀核的大小
    erosion = cv2.erode(img, kernel, iterations= 3)
    cv2.imshow('name', erosion)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


def dilErode(img): #图像膨胀操作
    kernel = np.ones((5, 5), np.uint8)
    dil_erosion = cv2.dilate(img, kernel, iterations= 3)
    cv2.imshow('name', dil_erosion)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


def MorphOpen(img): #图像的开运算, 先腐蚀再膨胀
    kernel = np.ones((5, 5), np.uint8)
    opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
    cv2.imshow('name', opening)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


def MorphClose(img):    #图像的闭运算, 先膨胀再腐蚀
    kernel = np.ones((5, 5), np.uint8)
    closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)
    cv2.imshow('name', closing)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


def gradint(img):#减法运算: 原图-腐蚀操作
    kernel = np.ones((5, 5), np.uint8)
    gradintion = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
    cv2.imshow('name', gradintion)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


def TopHat(img):#礼帽操作, 原始-开运算
    kernel = np.ones((2, 2), np.uint8)
    tophat = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)
    cv2.imshow('name', tophat)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


def BlackHat(img):#黑帽操作: 闭运算-原始输入
    kernel = np.ones((2, 2), np.uint8)
    blackhat = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel)
    cv2.imshow('name', blackhat)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值