简体   繁体   中英

OpenCV Splitting Contours

I'm trying to detect hand with OpenCV on Python.
I am working on this thresholded image:
阈值图像

And that's contour drawed state:
轮廓绘制的图像

I am trying to detect hand, but contour is too big, it captures my whole body.
I need it like this:
我需要这样


My code:

import cv2
orImage = cv2.imread("f.png")
image = cv2.cvtColor(orImage,cv2.COLOR_BGR2GRAY)
image = cv2.blur(image,(15,15))
(_,img_th) = cv2.threshold(image,96,255,1)
        (contours,_) = cv2.findContours(img_th, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
       if cv2.contourArea(c) > 15:
             x,y,w,h = cv2.boundingRect(c)
             cv2.rectangle(image,(x-20,y-20),(x+w+20,y+h+20),(0,255,0),2)
cv2.drawContours(image,contours,-1,(255,0,0),2)
cv2.imwrite("hi.jpg",image)




Thanks!

I have a solution (I got some help from HERE ), it has many other wonderful tutorials on image processing exclusively for OpenCV users.)

I first converted the image you have uploaded to HSV color space:

HSV = cv2.cvtColor(orimage, cv2.COLOR_BGR2HSV)

I then set an approximate range for skin detection once the image is converted to HSV color space:

l = np.array([0, 48, 80], dtype = "uint8")
u = np.array([20, 255, 255], dtype = "uint8")

I then applied this range to the HSV image:

skinDetect = cv2.inRange(HSV, l, u)

This is what I obtained (I also resized the image to make it smaller):

在此处输入图片说明

Now you can find the biggest contour in this image followed by morphological operations to obtain the hand perfectly.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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