def get_points(event, x, y, flags, param):
global lpnts, mode, counter, which_intersect
if event == cv2.EVENT_LBUTTONDOWN:
lpnts = np.append(lpnts, np.array([[x, y]]), axis=0)
cv2.polylines(img, [lpnts], False, (0, 0, 255))
if lpnts.size > 2:
if mode == 0:
#check(l1, lpnts[-1], lpnts[-2])
if check(l1, lpnts[-1], lpnts[-2]):
which_intersect = 0
mode = 1
#check(l2, lpnts[-1], lpnts[-2])
if check(l2, lpnts[-1], lpnts[-2]):
which_intersect = 1
mode = 1
elif mode == 1:
counter += 1
if check(lines[(which_intersect + 1) % 2], lpnts[-1], lpnts[-2]):
mode = 3
print counter
# check if the new point crosses a line
评论列表
文章目录