我想从实时视频流中检测我的手并创建一个手掩模。然而,我的结果很差,就像你在图片中看到的那样。
我的目标是跟踪手部运动,所以我将视频流从BGR转换为HSV颜色空间,然后进行阈值处理,以隔离手部的颜色,接着尝试查找手部轮廓,但最终结果并不是我想要达到的效果。
我该如何改进最终结果?
import cv2
import numpy as np
cam = cv2.VideoCapture(1)
cam.set(3,640)
cam.set(4,480)
ret, image = cam.read()
skin_min = np.array([0, 40, 150],np.uint8)
skin_max = np.array([20, 150, 255],np.uint8)
while True:
ret, image = cam.read()
gaussian_blur = cv2.GaussianBlur(image,(5,5),0)
blur_hsv = cv2.cvtColor(gaussian_blur, cv2.COLOR_BGR2HSV)
#threshould using min and max values
tre_green = cv2.inRange(blur_hsv, skin_min, skin_max)
#getting object green contour
contours, hierarchy = cv2.findContours(tre_green,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#draw contours
cv2.drawContours(image,contours,-1,(0,255,0),3)
cv2.imshow('real', image)
cv2.imshow('tre_green', tre_green)
key = cv2.waitKey(10)
if key == 27:
break
这里是带图片的链接:https://picasaweb.google.com/103610822612915300423/February7201303。 新的链接包含了图片轮廓、mask以及原始图片。 https://picasaweb.google.com/103610822612915300423/February7201304
以下是来自上述内容的样例图片: