简体   繁体   English

OpenCV Python中的手势

[英]Hand gesture in OpenCV python

I am trying to implement sign language interpreter using OpenCV library. 我正在尝试使用OpenCV库实现手语解释器。 to do this, i need to detect the hand gesture as a first phase. 为此,我需要将手势检测为第一阶段。 so basically i have achieved the detection of hand by converting the RGB color space into YCbCr, and then threshold the range of skin color. 因此,基本上,我已通过将RGB颜色空间转换为YCbCr,然后对肤色范围进行阈值来实现对手部的检测。

ycc = cv2.cvtColor(img , cv2.COLOR_BGR2YCR_CB)

min_ycc = np.array([0,133,85], np.uint8)
max_ycc = np.array([255,170,125], np.uint8 )
skin  = cv2.inRange(ycc, min_ycc, max_ycc)

opening = cv2.morphologyEx(skin, cv2.MORPH_OPEN, np.ones((5,5), np.uint8), iterations=3)
sure_bg = cv2.dilate(opening,np.ones((3,3),np.uint8), iterations=2)

_,contours,_ = cv2.findContours(sure_bg, cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE)

this code works fine with low detail backgrounds but has some noise if we have a detailed background that includes nearly skin colors. 此代码在细节背景较低的情况下也能正常工作,但如果我们的细节背景几乎包含肤色,则会产生一些干扰。
The only thing I have concern with is how to determine which contour is the hand contour. 我唯一关心的是如何确定哪个轮廓是手部轮廓。 I tried the maximum contour but it did not work out very accurately. 我尝试了最大轮廓,但效果不十分理想。

屏幕截图

You can remove background noises by erosion and dilation(morphological operations). 您可以通过腐蚀和膨胀(形态学操作)消除背景噪音。 Then you can set a threshold value for contour area(area=cv2.contourArea(cnt)) and filter out hand contour. 然后可以为轮廓区域设置一个阈值(area = cv2.contourArea(cnt))并过滤出手部轮廓。 The other way is to use histogram backprojection. 另一种方法是使用直方图反投影。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM