opencv_day5

avatar
作者
筋斗云
阅读量:0
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()   

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!