22 lines
549 B
Python
22 lines
549 B
Python
import numpy as np
|
|
import cv2
|
|
|
|
# ----- Helper Functions -----
|
|
def compute_distance(p1, p2):
|
|
return np.hypot(p2[0] - p1[0], p2[1] - p1[1])
|
|
|
|
# 4) compute straightness per finger
|
|
def finger_straight(i_tip, i_pip, i_mcp):
|
|
d1 = np.hypot(*(np.array(i_tip)-np.array(i_pip)))
|
|
d2 = np.hypot(*(np.array(i_pip)-np.array(i_mcp)))
|
|
return float(np.clip(d1/(d2+1e-3), 0, 1))
|
|
|
|
def yes_no():
|
|
while True:
|
|
key = cv2.waitKey(1) & 0xFF
|
|
|
|
if key == ord("y"):
|
|
return True
|
|
if key == ord("n"):
|
|
return False
|