PS. What kind of license you have for your software? Can I use a modified version of this function in a non-commercial research purpose? How do you want yourself to be mentioned if you allow the usage?
def calculateFingers(max_c):
"""
https://github.com/lzane/Fingers-Detection-using-OpenCV-and-Python/blob/master/new.py#L39-L60
"""
hull = cv2.convexHull(max_c, returnPoints=False)
if len(hull) > 3:
try:
defects = cv2.convexityDefects(max_c, hull)
except Exception:
defects = None
counter = 0
if defects is not None:
cavity_pts = []
for i in range(defects.shape[0]): # calculate the angle
s, e, f, d = defects[i][0]
start = tuple(max_c[s][0])
end = tuple(max_c[e][0])
far = tuple(max_c[f][0])
a = math.sqrt((end[0] - start[0]) ** 2 + (end[1] - start[1]) ** 2)
b = math.sqrt((far[0] - start[0]) ** 2 + (far[1] - start[1]) ** 2)
c = math.sqrt((end[0] - far[0]) ** 2 + (end[1] - far[1]) ** 2)
angle = math.acos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c)) # cosine theorem
if angle <= math.pi / 2: # angle less than 90 degree, treat as fingers
counter += 1
cavity_pts.append(far)
return counter, cavity_pts
return 0, []