使用opencvpython测量图像的椭圆度、矩形度和紧致度以进行形状消除

2024-06-23 19:47:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我要测量图像的椭圆度、矩形度和紧凑度。 这是我提取皮肤区域的代码,我要计算皮肤区域的椭圆度、矩形度和紧致度

# import the necessary packages
import numpy as np
import cv2

# define the upper and lower boundaries of the HSV pixel
# intensities to be considered 'skin'
lower = np.array([0, 48, 80], dtype="uint8")
upper = np.array([20, 255, 255], dtype="uint8")
frame = cv2.imread("image/girl2.jpg")

#frame = imutils.resize(frame, width=400)
converted = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
skinMask = cv2.inRange(converted, lower, upper)

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11, 11))
skinMask = cv2.erode(skinMask, kernel, iterations=2)
skinMask = cv2.dilate(skinMask, kernel, iterations=2)

# blur the mask to help remove noise, then apply the
# mask to the frame
skinMask = cv2.GaussianBlur(skinMask, (3, 3), 0)
skin = cv2.bitwise_and(frame, frame, mask=skinMask)

# show the skin in the image along with the mask
#cv2.imshow("images", skin)
cv2.waitKey(0)

Tags: thetoimportnpmaskcv2upperkernel

热门问题