Using cv.jit.touches: recycling index values

cv.jit.touches, a new object added in the 1.7.0 release, tracks the movement of bright spots in a greyscale image and reports “touch”, “drag” and “release” information ? when regions appear, move or disappear. Each region is assigned a unique ID number, so that even if they move, you can always know where an object is from frame to frame. This is unlike using cv.jit.label-based blob analysis, where you are never guaranteed that the same object in a scene will end up with the same index.

By default, cv.jit.touches outputs ever-increasing indices, although the counter is always reset to 0 when there are no active regions. For some applications, this is a reasonable approach: every touch event has its own unique ID. However, some may wish to recycle IDs. If you’re in this situation, I made an abstraction that renumbers the IDs coming out of cv.jit.touches to re-use release IDs, and keep their values as low as possible. It will always output the smallest value that isn’t currently assigned to another active region.

Download cv.jit.touches.recycle.

In order to use this file, just copy it to the “Max5/Cycling ’74/cv.jit-support/Abstractions” folder.

You can see how it works by copying the following code and selecting the “new from clipboard” option from Max’s file menu.


----------begin_max5_patcher----------
911.3oc0XssbhBDD8Y8qfhmcslaL.6a6Ovturus0VoPXhRJfwBFiIap7uuLW
zPRDbTPzTQfLyfNm9zce5FdY5D2E7mXUtNe24ONSl7xzISTSImXhY7D27nmh
yhpT2laLOOmUHbmoWSvdRnl+2qJYLmEY7EU6VqXSdZQFSn9hv2ljuQraVfY1
0Qh3UoEKuqjEKzvgR7lCl4.AgxK9pyH3bfyeMemzD0FyW7v27g61y64Ehhnb
lZoeTlFk0bkpz+oVAhmCjy95zoxSy5qsukOjVNwm1zxwcZ4fqpk+qBsOeXLb
LDYsgSCupF9OGTONBCs2vCFECOmUUEsj8ICONiEUNyYcTZgf+XTliGP9ABTG
MW.Jmt9.ATGebIpdEHrdkEQEKadd2tlkVvh4aJTaM4PTM5fTMrKYEcxEQGpE
n3ZJoEtldbtVushmWyzafq69eoAvMTv1VCjO4Ex3QIMIJKB+5fSLJs5rOIWz
QzG9LXDERGAVI9w4OjJlK3ahWwplmTFs8fDD4TIHOOUhIlpqBA75jhfmAEUi
66xiDkoOMnDkjNVuMsHgumIVWxEb4NuGYXDXwyHB3DBlPGkqH.UlU8ush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