opencv_day5
创始人
2024-11-14 12:05:54
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()   

相关内容

热门资讯

裸辞做“一人公司”,我后悔了 去年这个时候,一位以色列程序员正在东南亚旅行。他顺手把一个在脑子里转了很久的想法做成了产品,一个让任...
南京建成国内首个Pre-6G试... 4月21日,2026全球6G技术与产业生态大会在南京开幕。全息互动技术展台前,一名远在北京的工作人员...
超梵求职受邀参加“2025抖音... 超梵求职受邀参加“2025抖音巨量引擎成人教育行业生态大会”,探讨分享优质内容传播,服务万千学员。 ...
摩托罗拉Razr 2026(R... IT之家 4 月 22 日消息,摩托罗拉宣布新一代 Razr 折叠手机将于 4 月 29 日在美国发...
库克卸任,特纳斯领航:苹果新纪... 苹果首席执行官蒂姆·库克将卸任,硬件工程主管约翰·特纳斯将接任,苹果公司今天宣布此事。 库克将在夏季...