Skip to content

Instantly share code, notes, and snippets.

@AdroitAnandAI
Last active September 16, 2021 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdroitAnandAI/6d9dbad0d8488aff0a6335ea7c0f49ab to your computer and use it in GitHub Desktop.
Save AdroitAnandAI/6d9dbad0d8488aff0a6335ea7c0f49ab to your computer and use it in GitHub Desktop.
To detect the object movement in circular motion
# loop over the set of tracked points
for i in range(1, len(pts)):
# if either of the tracked points are None, ignore them
if pts[i - 1] is None or pts[i] is None:
continue
# otherwise, compute the thickness of the line and draw the connecting lines
thickness = int(np.sqrt(args["buffer"] / float(i + 1)) * 2.5)
cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness)
isCirclePts = [p for p in pts if p is not None]
if (len(isCirclePts) > 30):
vectors = [np.subtract(t, s) for s, t in
zip(isCirclePts, isCirclePts[1:])]
vectors = [vector for vector in vectors
if np.linalg.norm(vector) > 5]
# To find concavity, check vector direction using Right Hand rule
determ = [np.linalg.det([s, t])
for s, t in zip (vectors, vectors[1:])]
directionChange = [determ[i] * determ[i + 1]
for i in range (len(determ) - 1)]
# when the movement of the object is
# insignificant, consider it stationary
if len(directionChange) < 10:
alarmTriggered = False
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment