Identifying the position of a moving animal

Hi there,

I just got one OpenMV cam 7 but i’m totally new to machine vision.
I need to use openmv cam to identify the position of an animal in the box. The box has left and right chambers, and the animal can freely go to either left or right side.
Once the animal was detected in each side, a TTL trigger will send out through different pins. Is there an example can do this kind project?
Thanks so much!


Hi, the easiest ways to do this are to use color tracking on the inverse of the color of the box. This will detect the animal. Is the box well lit? If so, then checkout the Color-Tracking Example scripts under OpenMV IDE and then use the Tools->Machine Vision->Threshold Editor to get the color tracking settings. Note that you want to pass the inverse flag to the find_blob() method to find everything not the color of the box.

Thanks for the useful reply, i just tried and it indeed can track the moving animal. My following question is how do i know the position (or coordinate) of the moving animal? and

I would also like to tell if there is an animal in a scene but it is outside with clutter. I am thinking I would just like to know if the two images are similar (using the similarity class). Do you have any advice ? I think gray images would work.

Could I get similarity (similarity = fb.get_similarity(previousImage)) to use thresholds that are different for the top rows than the bottom rows. This is because the the top rows would mean that the animal is farther. I want to filter out smaller animals.

The get similarly method is for perfect image to image comparisons.

Um, can you state your problem domain here? We specifically built the new H7 camera with thermal imaging support for this type of application so it’s easy to do well and it will work in both night and day.

Perfect, I pre-ordered the H7 yesterday.

Do you recommend the blob with the H7? I could generate a list of the blobs and compare these blob positions to see if the animals are moving. This will also allow me to know the row that the blob started so I can estimate animal size.

When will the thermal documentation (H7) be out?

My system I am building cannot cost too much. I need to see if I can recognize animal movement without the thermal sensor.

Do you recommend the blobs with gray image?

Hi, with a grayscale image you can do frame differencing to see what’s changing against the background. This works well assuming there are no shadows and changing lighting.

Hi all! We seem to be working on a very similar application! Check out our project here, based on the M7, it works super well for detecting animals!

We also would like it to trigger a TTL line when the animal is in one half of the box. However I’m having a weird issue with this at the moment. We are using the LCD shield, and are using P6 for an output to take advantage of the DAC and ADC for future applications (I guess for this application we could use any free pin). We also physically disconnected P6 from the LCD shield so our pulses on P6 wouldn’t also do brightness control.

Long story short, when I hook P6 up to an oscilloscope I see output as expected, it goes high (3.3V) when the centroid[1] of the blob is <80 (see code below). However, when I hook P6 up to equipment (an LED driver) nothing happens. It doesn’t seem to source enough current to trigger the LED driver. Any ideas on why P6 wouldn’t be able to trigger an LED driver? Is there something special I need to do with P6 to enable it to work this way?

We’re setting up the output on P6 in the code with:

# Set up Analog Output
dac = pyb.DAC(pyb.Pin('P6'))

And triggering the output during the loop with:

if centroid[1] < 80:


Hi, did you connect the two grounds between the two devices?

Note, you don’t need to out the pin into DAC mode. You can use it as a regular GPIO. Try that instead of DAC mode. The pin might not be able to handle a large load in DAC mode and might expect a low impedance.

Thanks for the quick reply!

Turns out the problem was the DAC mode. I put P6 in normal GPIO mode with:

out = pyb.Pin("P6", pyb.Pin.OUT_PP)

And it works now, thanks!