Ball detection in low light environment

I’m working on a project that aims to detect an 8 inch diameter ball about 20 feet away from the camera, and only when it is in motion. I’m using the following technique:

  1. Capture image when starting the camera
  2. Begin frame differencing
  3. Convert the frame to binary with a threshold of 25
  4. Perform erosion and dilation to get rid of noise and segmented objects
  5. Use blob detection to identify objects that are roughly ball size or bigger.
  6. If the centroid is above a specific line we know it’s in flight and moving. Ignore anything larger or below that threshold

This worked relatively well so long as there was good contrast between the ball and background. And so long as the background didn’t change which pretty much means this doesn’t work outside.

My main issue is trying to deploy this in a new environment where the lighting is poor. The ball is really only lit from the top meaning the entire lower half of the ball is in shadow and it just gets lost in the background.

I noticed that auto exposure was resulting in a relatively dark image, perhaps incorrectly metered by a few bright ceiling lights. If I manually set the exposure I could lighten the image and get better results, but there were then many more false positives.

I think my quick fix is to install some bright lights behind the camera to better illuminate the balls. I’d like to find a more robust way to account for this though. And I’m realizing it likely will require some conditional evaluation of blobs frame over frame.

Any guidance on this would be greatly appreciated.

You could just use Edge Impulses FOMO network to track the ball object. It will generalize better to new environments.

The traditional methods are great as long as the subject matter is fixed along with lighting and it’s inside.

Perhaps I need to try that again. I was training a model specifically for volleyballs with a few thousand images, but was seeing relatively poor results and nearly 1 frame per second output. For this application I need something like 15 FPS or higher to be successful.

FOMO should provide 30 FPS or so.

@kwagyeman changing the lighting has helped significantly. I’ve noticed though that auto exposer can sometimes over or under expose the region of interest. If I set a manual exposure I can optimize for performance in this region, but it does not adjust for lighting changes at different times of the day.

Is there a way to set auto exposure for a specific region, or to manually set the exposure based on a more robust set of conditions?

Yeah, you can mess with how the auto exposure algorithm is controlled via direct register writes to the camera and looking at the camera datasheet. See the sensor.__write_reg() function.

As for manually setting it using our API, you can use get_stats() to get information about the scene lighting and then adjust the exposure based on that yourself.