计算机视觉:掩盖人的手 [英] Computer Vision: Masking a human hand

查看:242
本文介绍了计算机视觉:掩盖人的手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从现场视频流检测我的手,并创建我的手的面具。但是我得到的结果很糟糕,你可以从图片看到。

I'd like to detect my hand from a live video stream and create a mask of my hand. However I'm reaching quite a poor result, as you can see from the picture.

我的目标是跟踪手的动作,所以我做的是转换视频从BGR到HSV颜色空间的流,然后我阈值图像为了隔离我的手的颜色,然后我试图找到我的手的轮廓,虽然最终的结果不是我想要实现的。

My goal is to track the hand movement, so what I did was convert the video stream from BGR to HSV color space then I thresholded the image in order to isolate the color of my hand, then I tried to find the contours of my hand although the final result isn't quite what I wanted to achieve.

如何提高最终结果?

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
具有图像加轮廓,蒙版和原始的新链接。
https://picasaweb.google.com/103610822612915300423/February7201304

下面是一个来自上面的示例图片:

And here's a sample picture from above:

推荐答案

是执行逐像素阈值以将皮肤像素与非皮肤像素分离的许多方式,并且存在基于实际上任何色彩空间(甚至具有RGB)的论文。所以,我的回答是简单地基于使用肤色地图在可视电话应用程序中的面部分割Chai和Ngan。他们使用YCbCr色彩空间,得到相当不错的结果,本文还提到了一个阈值,对他们有效:

There are many ways to perform pixel-wise threshold to separate "skin pixels" from "non-skin pixels", and there are papers based on virtually any colorspace (even with RGB). So, my answer is simply based on the paper Face Segmentation Using Skin-Color Map in Videophone Applications by Chai and Ngan. They worked with the YCbCr colorspace and got quite nice results, the paper also mentions a threshold that worked well for them:

(Cb in [77, 127]) and (Cr in [133, 173])

Y 渠道未指定,但有论文提及 Y> 80 。对于你的单张图像, Y 在整个范围内都很好,即实际上不区分皮肤。

The thresholds for the Y channel are not specified, but there are papers that mention Y > 80. For your single image, Y in the whole range is fine, i.e. it doesn't matter for actually distinguishing skin.

这里是输入,根据所提到的阈值的二进制图像,以及丢弃小组件后产生的图像。

Here is the input, the binary image according to the thresholds mentioned, and the resulting image after discarding small components.

import sys
import numpy
import cv2

im = cv2.imread(sys.argv[1])
im_ycrcb = cv2.cvtColor(im, cv2.COLOR_BGR2YCR_CB)

skin_ycrcb_mint = numpy.array((0, 133, 77))
skin_ycrcb_maxt = numpy.array((255, 173, 127))
skin_ycrcb = cv2.inRange(im_ycrcb, skin_ycrcb_mint, skin_ycrcb_maxt)
cv2.imwrite(sys.argv[2], skin_ycrcb) # Second image

contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, 
        cv2.CHAIN_APPROX_SIMPLE)
for i, c in enumerate(contours):
    area = cv2.contourArea(c)
    if area > 1000:
        cv2.drawContours(im, contours, i, (255, 0, 0), 3)
cv2.imwrite(sys.argv[3], im)         # Final image

最后,有一个相当不错的论文,不依赖于个别像素分类这个任务。相反,它们从已知包含皮肤像素或非皮肤像素的标记图像的基础开始。从中,他们训练,例如,一个SVM,然后基于这个分类器区分其他输入。

Lastly, there are a quite decent amount of papers that do not rely on individual pixel-wise classification for this task. Instead, they start from a base of labeled images that are known to contain either skin pixels or non-skin pixels. From that they train, for example, a SVM and then distinguish other inputs based on this classifier.

这篇关于计算机视觉:掩盖人的手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆