皮肤检测后如何分别检测手部?

时间:2017-01-16 08:14:13

标签: python opencv

我已经使用皮肤检测来检测皮肤颜色,但在此过程中其他身体部位也会被检测到。是否有可能单独检测手或是否有任何算法来区分手和身体?

这是图片:

我的代码如下:

import numpy as np
import cv2



cap = cv2.VideoCapture(0)
while(True):
   ret,frame=cap.read()

   HSV = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
   l = np.array([0, 50, 80], dtype = "uint8")
   u = np.array([23, 255, 255], dtype = "uint8")
   skinDetect = cv2.inRange(HSV, l, u)
   cv2.imshow('Masked Image',skinDetect)
   _,contours, hierarchy = cv2.findContours(skinDetect,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
   for cnt in contours:
    x,y,w,h = cv2.boundingRect(cnt)
      # discard areas that are too small
    if h<30 or w<30:
        continue
    cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
   cv2.imshow('Rectangle',frame)
   if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

0 个答案:

没有答案