opencv_day5
咕噜咕嘟嘟嘟 2024-08-04 09:01:06 阅读 50
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()
上一篇: 【JAVA设计模式】适配器模式——类适配器模式详解与案例分析
下一篇: AI Engineer正在崛起;转型AI工程师的必学资料清单;如何招聘&培养一名AI工程师;AI Engineer最全面经&题库 | ShowMeAI日报
本文标签
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。