|
91 | 91 | " cv2.circle(img, (int(x), int(y)), int(radius),\n", |
92 | 92 | " (0, 255, 255), 2)\n", |
93 | 93 | " 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 | + " " |
95 | 134 | ] |
96 | 135 | }, |
97 | 136 | { |
|
243 | 282 | "name": "python", |
244 | 283 | "nbconvert_exporter": "python", |
245 | 284 | "pygments_lexer": "ipython3", |
246 | | - "version": "3.6.1" |
| 285 | + "version": "3.5.4" |
247 | 286 | } |
248 | 287 | }, |
249 | 288 | "nbformat": 4, |
|
0 commit comments