形态学操作用于提取在区域形状表示和描述中有用的图像成分。形态学操作是一种基于图像形状的基本操作。它通常在二值图像上执行。它需要两个数据源,一个是输入图像,另一个是结构化组件。形态操作符以输入图像和结构组件作为输入,然后使用集合操作符组合这些元素。输入图像中的对象根据图像形状的属性进行处理,这些属性被编码在结构化组件中。
开放与侵蚀相似,因为它倾向于从前景像素区域的边缘去除明亮的前景像素。操作员的作用是在剔除前景像素的其他区域的同时,保护与结构组件相似的前景区域,或者完全包含结构组件的前景区域。打开操作用于去除图像中的内部噪声。
语法:cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)参数:
-> image:输入图像数组。
-> cv2.MORPH_OPEN:应用形态打开操作。
->kernel:结构元素。
以下是解释开放形态操作的Python代码-
# Python programe to illustrate
# Opening morphological operation
# on an image
# organizing imports
import cv2
import numpy as np
# return video from the first webcam on your computer.
screenRead = cv2.VideoCapture( 0 )
# loop runs if capturing has been initialized.
while ( 1 ):
# reads frames from a camera
_, image = screenRead.read()
# Converts to HSV color space, OCV reads colors as BGR
# frame is converted to hsv
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# defining the range of masking
blue1 = np.array([ 110 , 50 , 50 ])
blue2 = np.array([ 130 , 255 , 255 ])
# initializing the mask to be
# convoluted over input image
mask = cv2.inRange(hsv, blue1, blue2)
# passing the bitwise_and over
# each pixel convoluted
res = cv2.bitwise_and(image, image, mask = mask)
# defining the kernel i.e. Structuring element
kernel = np.ones(( 5 , 5 ), np.uint8)
# defining the opening function
# over the image and structuring element
opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
# The mask and opening operation
# is shown in the window
cv2.imshow( 'Mask' , mask)
cv2.imshow( 'Opening' , opening)
# Wait for 'a' key to stop the program
if cv2.waitKey( 1 ) & 0xFF = = ord ( 'a' ):
break
# De-allocate any associated memory usage
cv2.destroyAllWindows()
# Close the window /Release webcam
screenRead.release()
输入框:
面具:
输出框架:
系统将定义的蓝皮书识别为输入, 并通过打开功能简化了感兴趣区域中的内部噪音。
首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。
来源:
https://www.srcmini02.com/69842.html