Skip to content

Commit ae17946

Browse files
committed
iterating over tracked points done for direction
1 parent 779e38a commit ae17946

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

object_track.ipynb

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,46 @@
9191
" cv2.circle(img, (int(x), int(y)), int(radius),\n",
9292
" (0, 255, 255), 2)\n",
9393
" cv2.circle(img, center, 5, (0, 0, 255), -1)\n",
94-
" pts.appendleft(center)"
94+
" pts.appendleft(center)\n",
95+
" # loop over the set of tracked points\n",
96+
" for i in np.arange(1, len(pts)):\n",
97+
" # if either of the tracked points are None, ignore\n",
98+
" # them\n",
99+
" if pts[i - 1] is None or pts[i] is None:\n",
100+
" continue\n",
101+
" # check to see if enough points have been accumulated in\n",
102+
" # the buffer\n",
103+
" if counter >= 10 and i == 1 and pts[-10] is not None:\n",
104+
" # compute the difference between the x and y\n",
105+
" # coordinates and re-initialize the direction\n",
106+
" # text variables\n",
107+
" dX = pts[-10][0] - pts[i][0]\n",
108+
" dY = pts[-10][1] - pts[i][1]\n",
109+
" (dirX, dirY) = (\"\", \"\")\n",
110+
"\n",
111+
" # ensure there is significant movement in the\n",
112+
" # x-direction\n",
113+
" if np.abs(dX) > 20:\n",
114+
" dirX = \"East\" if np.sign(dX) == 1 else \"West\"\n",
115+
"\n",
116+
" # ensure there is significant movement in the\n",
117+
" # y-direction\n",
118+
" if np.abs(dY) > 20:\n",
119+
" dirY = \"North\" if np.sign(dY) == 1 else \"South\"\n",
120+
"\n",
121+
" # handle when both directions are non-empty\n",
122+
" if dirX != \"\" and dirY != \"\":\n",
123+
" direction = \"{}-{}\".format(dirY, dirX)\n",
124+
"\n",
125+
" # otherwise, only one direction is non-empty\n",
126+
" else:\n",
127+
" direction = dirX if dirX != \"\" else dirY\n",
128+
" # otherwise, compute the thickness of the line and\n",
129+
" # draw the connecting lines\n",
130+
" thickness = int(np.sqrt(15 / float(i + 1)) * 2.5)\n",
131+
" cv2.line(img, pts[i - 1], pts[i], (0, 0, 255), thickness)\n",
132+
"\n",
133+
" "
95134
]
96135
},
97136
{
@@ -243,7 +282,7 @@
243282
"name": "python",
244283
"nbconvert_exporter": "python",
245284
"pygments_lexer": "ipython3",
246-
"version": "3.6.1"
285+
"version": "3.5.4"
247286
}
248287
},
249288
"nbformat": 4,

0 commit comments

Comments
 (0)