How to count the number of faces

HumanNature's icon

Hi Everyone,
I'm trying to set up a patch with the cv.jit.faces object and I need some sort of attribute that gives me the ability to count the number of faces of detected. You see, I want the patch to do one thing if there are LESS than 3 faces and another if there are MORE than 3.

I hope my question is clear and I would really appreciate anyone to share some thoughts on the problem at hand.

Thanks!

bart at max (previously BITter)'s icon

This solution is mentioned in the [cv.jit.faces] help file.

Send message getnfaces to [cv.jit.faces] connect to the second outlet [route nfaces] with a [number] box and you have what you want.

MIB's icon

another way would be to use jit.iter to get the count of the faces. since you have to use jit.iter in any case to do anything useful. use the middle outlet to get the instance number. look for the highest number + 1 and you have the amount of faces found (+1 because they are indexed from 0).

HumanNature's icon

BITter, thank you for your reply but I checked the help file and tried the getnfaces message, and I was unable to make any use of it.

Max Patch
Copy patch and select New From Clipboard in Max.

MIB, thank you as always for your immediate response. I'm trying to do what you said, but for some reason I can't seem to piece the parts together. Do you mind taking a look at what I've put together so far?

Thanks!

HumanNature's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I did this, but for some reason, it only starts counting after there is more than one face??

MIB's icon
Max Patch
Copy patch and select New From Clipboard in Max.

it's indexed from 0 so your first face is 0!!

HumanNature's icon
Max Patch
Copy patch and select New From Clipboard in Max.

If you don't mind, this is what I got so far, could you take a look at this?

MIB's icon
Max Patch
Copy patch and select New From Clipboard in Max.

how about something like this:

bart at max (previously BITter)'s icon
Max Patch
Copy patch and select New From Clipboard in Max.

It should work like this: