Articles

Content You Need: cv.jit

Not long ago, we received a message from an old friend, Jean-Marc Pelletier, the creator and maintainer of the cv.jit package. He let us know that he dusted off the old cv.jit repository and knocked together some new goodies to share with the Max community.

For those of you who may not be familiar with it, cv.jit is an incredible package of tools geared toward computer vision techniques that are built upon the open source OpenCV library. The message of a new version from Jean-Marc was a welcome one - it has been a while since the last update to this package. So we got to work putting a new release together that you can now access using the Max Package Manager.

Release 2.0 of the cv.jit package offers not only existing feature updates, but also an extensive reworking of the package's help files that make exploring the old (and new!) features of cv.jit more straightforward. I’d like to highlight some of the exciting things you can do with this new cv.jit release.

As with any Package Manager release, the easiest place to start is the launcher patch, accessible from the Package Manager itself or by locating the launcher patch in Max's Extras menu.

You can open the cv.jit launch patcher from the Package Manager, or from Max's Extras menu

If you're familiar with the previous cv.jit guide, the improvements here are immediately obvious — objects and abstractions in the package are grouped together by category based on their function for ease of navigation. There's even a "new!" category that lists the tools introduced in this update.

These categories will help you to have a better idea of where to look for when, for example, you are only interested in performing simple blob tracking. Clicking the blobs category in the launcher patch and clicking on cv.jit.blobs.centroids opens up the new and improved help patch.

cv.jit.blobs.centroids help patch

Most help files now include a bpatcher utility to manage input sources and common matrix operations that are often necessary for tracking with cv.jit. This abstraction is accessible via the clickable label in the launcher patch.

Unlock the patch and click on the Patching Mode icon on the bottom toolbar to display the abstraction's contents.

cv.jit input chooser utility

The process chain is organized as follows: cv.jit.resizejit.rgb2lumajit.op @op >jit.gen (inverter). Here's how the objects work together:

  • cv.jit.resize is useful both for bringing down the number of pixels needed to process, as well as conforming the input to an expected size to match pwindow sizes in some help files.

  • jit.rgb2luma converts to single-plane data required by several cv.jit objects.

  • jit.op converts to binary data (pixels that are either on or off) for objects that expect it.

  • jit.gen performs an invert operation for cases where the foreground is darker than the background.

Let's take a look at some of the new objects and abstractions in the package:

Matrix-heads should not miss the cv.jit.iter (iterate by row or column), cv.jit.changetype (easily change the type of a matrix e.g. from char to float32) and cv.jit.notempty (I’ll let you guess) utilities.

I’m definitely going to experiment with cv.jit.kalman and cv.jit.lowpass next time I have a noisy sensor data stream to process. Additionally, cv.jit.noise provides some fantastic new options for generating random floating-point values.

You'll find some meatier stuff in the cv.jit.face and cv.jit.keypoints object families.

Although we're getting into some incredibly complex computer vision algorithms, Jean-Marc has provided extensive help files that explain the process, helper abstractions for some common use cases, and drawing utilities to visualize the output.

cv.jit.keypoints.match help patch - keypoints from the bug image on the right are matched to the image on the left

There's a lot of amazing new options in this release, and the new design makes exploring and finding the objects and abstractions you need much easier. Fire up your Package Manager, download the cv.jit 2.0 package, and have fun!

by Rob Ramirez on March 30, 2021

Creative Commons License
Linden's icon

great news:) unfortunately i get some errors with the new stuff:

cv_jit_face_landmarks: OpenCV error: OpenCV(4.5.0) /Users/rob/dev/opencv/opencv-4.5.0/modules/core/src/matrix.cpp:473: error: (-215:Assertion failed) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function 'Mat'

any idea how this can be solved?

Rob Ramirez's icon

patch? object? system specs? max version?

Linden's icon

sorry for not being specific - it happens with the patches in the "new"category"
i think it is the cv.jit.face.landmarks object which causes the errors .

i am on mac osc 10.14 i7 3.1 ghz latest max version

Rob Ramirez's icon

help file works fine over here, so will need some steps to reproduce.