代码拉取完成,页面将自动刷新
import numpy as np
import cv2
camera = cv2.VideoCapture(0)
# determine upper and lower HSV limits for (my) skin tones
lower = np.array([0, 100, 0], dtype="uint8")
upper = np.array([50,255,255], dtype="uint8")
while (True):
ret, frame = camera.read()
if not ret:
continue
# switch to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# find mask of pixels within HSV range
skinMask = cv2.inRange(hsv, lower, upper)
# denoise
skinMask = cv2.GaussianBlur(skinMask, (9, 9), 0)
# kernel for morphology operation
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (4, 4))
# CLOSE (dilate / erode)
skinMask = cv2.morphologyEx(skinMask, cv2.MORPH_CLOSE, kernel, iterations = 3)
# denoise the mask
skinMask = cv2.GaussianBlur(skinMask, (9, 9), 0)
# only display the masked pixels
skin = cv2.bitwise_and(frame, frame, mask = skinMask)
cv2.imshow("HSV", skin)
# quit or save frame
key = cv2.waitKey(1000 // 12) & 0xff
if key == ord("q"):
break
if key == ord("p"):
cv2.imwrite("skin.jpg", skin)
cv2.destroyAllWindows()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。