opencv - Dectection of finger tip -


i trying calculate pose of hand in image. so, have extracted hand image. extract finger tip hand have used convexhull(). getting error "points not numpy array, neither scalar".

here code:

import numpy np import cv2  img = cv2.imread("hand.jpg") hsv = cv2.cvtcolor(img,cv2.color_bgr2hsv); lower_hand = np.array([0,30,60]) upper_hand = np.array([20,150,255])  mask = cv2.inrange(hsv, lower_hand, upper_hand)  res = cv2.bitwise_and(img, img, mask=mask)  derp,contours,hierarchy = cv2.findcontours(mask,cv2.retr_tree,cv2.chain_approx_simple) hull = cv2.convexhull(contours) print hull cv2.drawcontours(img, contours, -1, (0,255,0), 3) 

findcontours returns: "detected contours. each contour stored vector of points." , convexhull() needs 2d point set. think need loop this, so:

    cnt in contours:         hull = cv2.convexhull(cnt)         cv2.drawcontours(img,[cnt],0,(0,255,0),2)         cv2.drawcontours(img,[hull],0,(0,0,255),2) 

full working code:

import numpy np import cv2  img = cv2.imread("hand.jpg") hsv = cv2.cvtcolor(img,cv2.color_bgr2hsv); lower_hand = np.array([0,30,60]) upper_hand = np.array([20,150,255])  mask = cv2.inrange(hsv, lower_hand, upper_hand)  res = cv2.bitwise_and(img, img, mask=mask)  #"derp" wasn't needed in code tho.. derp,contours,hierarchy = cv2.findcontours(mask,cv2.retr_tree,cv2.chain_approx_simple) cnt in contours:     hull = cv2.convexhull(cnt)     cv2.drawcontours(img,[cnt],0,(0,255,0),2)     cv2.drawcontours(img,[hull],0,(0,0,255),2)  cv2.imshow('image',img) cv2.waitkey(0) cv2.destroyallwindows() 

result:

enter image description here


Comments