How much CPU power is needed to detect a cat? - Page 1
Forum section: electronics / projects

author: peter-h
author_rank: Super Contributor
timestamp: July 22, 2021, 01:19:19 pm
content: Anyone living in the countryside and seeing a constant stream of birds and small animals killed just for fun, not eaten, will understandA hypothetical product: a camera (visual or IR) which can detect a cat, and then one could aim a water spray at it, and track it with it. The spray would be guided by two servo motors.These things already exist but they use a normal PIR sensor and trigger a nozzle which rapidly oscillates (the L-R movement is driven by the water pressure; no motor) and sprays water over an arc of about 90 degrees.Veryeffective but the cat has to walk right past it, but it also sprays anybody walking past and soaks themAlso PIR sensors get triggered by vegetation or anything moving about in the wind, which is a big issue with PIR-triggered security lights etc (they basically don't work).Dogs would be very hard to distinguish from cats but they don't normally roam freely, whereas most cat owners (around here) let them out all day. And if "you" don't have a cat also, they will roam around your garden, killing everything they see.For it to work at night it would have to use an IR (FLIR) camera, and they aren't cheap.It is obviously possible - there is software to detect all kinds of things, to prevent people posting dodgy stuff on social media, for removing car number plates, for blanking out faces, etc. But all this has huge CPU power at its disposal.I think doing it using a FLIR sensor (doing it wholly in the deep-IR spectrum) might be the simplest way, and looking for a self contained "blob", whereas a human walking would have different proportions.

author: nali
author_rank: Frequent Contributor
timestamp: July 22, 2021, 02:12:30 pm
content: That can be done pretty easy with a Raspberry Pi, OpenCV and a bit of Python (including the servo control). I did sort of the same thing for fox detection and got as far as aiming the camera at a target, but it got put on the slightly overloaded "I'll finish it some day" shelf.

author: peter-h
author_rank: Super Contributor
timestamp: July 22, 2021, 03:02:29 pm
content: I am sure it would take more than "a bit of Python" to detect the shape of a catUnless Python is a lot more clever than I thought...How did you do it?Assuming one goes for shape detection, there must be an image sensor interface, which the CPU uses to grab frames into RAM, for image processing. Then the clever stuff starts.

author: Siwastaja
author_rank: Super Contributor
timestamp: July 22, 2021, 03:19:38 pm
content: The magic is not in Python;As usual, "use Python" is a shorthand for:This is already implemented as a ready-to-go solution, engineered with decades and decades of experience, in millions of lines of C, asm, Verilog, C++, CUDA or opencl or whatever, et cetera et cetera.Then you have a Python library that acts as a wrapper so you instantiate the whole complex shebang and "detect a cat". I'm almost sure someone have already did the hard work of teaching the neural network with gazillion of images of "this is a cat" and "this is not a cat".Still, such "AI" pattern detection is still far from being intelligent, or reliable. It can likely detect a cat in a suitably constrained environment, though.

author: nali
author_rank: Frequent Contributor
timestamp: July 22, 2021, 03:41:10 pm
content: I was just mucking about so didn't do anything other than some basic movement detection using openCV's libraries. Essentially you end up with a bounding box and can decide based on the dimensions. I believe It is possible to do some shape detection or pattern matching using openCV although you won't be able to differentiate between a cat or say a badger - you're then talking using AI to look at behaviour but then of course you've also upped the complexity by an order of magnitude.https://www.pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/Rather than track, I was slewing the camera to move the target to the centre of the screen. I was using a Pi Zero W and it ran, though only just - it needs a "proper" Pi really.Edit: this was using the standard Pi camera BTW (There is an IR sensitive version available pretty cheap too)

author: mazurov
author_rank: Frequent Contributor
timestamp: July 22, 2021, 05:06:47 pm
content: Nvidia Jetson will work here (even Nano). IIRC they have an example application covering this very case. Can be also scaled up to target just about anything moving while recognizable from the background.

author: rstofer
author_rank: Super Contributor
timestamp: July 22, 2021, 08:37:58 pm
content: To start, Google for 'python image classification' - there will be several ways to get images classified.Maybe something like this will be helpful:https://machinelearningmastery.com/how-to-develop-a-convolutional-neural-network-to-classify-photos-of-dogs-and-cats/Yes, it takes something larger than an Arduino. I don't see why it wouldn't work on a Pi but the Jetson Nano is probably a better choice and NVIDIA has a tutorial on classification using the Nano.Google for 'jetson nano image classification' and watch a bunch of videos to see if there is anything interesting.

author: peter-h
author_rank: Super Contributor
timestamp: July 22, 2021, 08:56:36 pm
content: That is amazing stuff!Clearly it needs something PC-level, not a little embedded CPU like a 32F4. The amount of data is huge, for a start. I am not surprised some are using graphics cards.Perhaps the solution is to just try to identify a "blob" on an FLIR camera image.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: July 22, 2021, 09:18:40 pm
content: It's been done, of courseSource is here,https://github.com/TucoFlyerappears the tracking is done in the OBS plugin.She says it runs on a "fairly powerful" GPU (though it's not apparent how much capacity it's using?). I'm sure there are lighter weight algorithms as well; I think I've seen similar on a rPi as suggested above.Tim

author: Marco
author_rank: Super Contributor
timestamp: July 23, 2021, 08:24:40 am
content: Quote from: peter-h on July 22, 2021, 08:56:36 pmStill probably want to take into account size so you don't spray birds, but it does simplify the artificial stupidity.

author: DrG
author_rank: Super Contributor
timestamp: July 23, 2021, 03:21:01 pm
content: *drat* Felix foils my cat detector yet again!