Take the 2-minute tour ×
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It's 100% free, no registration required.

I have a hobby project which I am contemplating committing to as a way of increasing my so far limited experience of machine learning. I have taken and completed the Coursera MOOC on the topic. My question is with regards to the feasibility of the project.

The task is the following:

Neighboring cats are from time to time visiting my garden, which I dislike since they tend to defecate on my lawn. I would like to have a warning system that alerts me when there's a cat present so that I may go chase it off using my super soaker. For simplicity's sake, say that I only care about a cat with black and white coloring.

I have setup a raspberry pi with camera module that can capture video and/or pictures of a part of the garden.

Sample image:

Sample garden image

My first idea was to train a classifier to identify cat or cat-like objects, but after realizing that I will be unable to obtain a large enough number of positive samples, I have abandoned that in favor of anomaly detection.

I estimate that if I captured a photo every second of the day, I would end up with maybe five photos containing cats (out of about 60,000 with sunlight) per day.

Is this feasible using anomaly detection? If so, what features would you suggest? My ideas so far would be to simply count the number of pixels with that has certain colors; do some kind of blob detection/image segmenting (which I do not know how do to, and would thus like to avoid) and perform the same color analysis on them.

share|improve this question
1  
Perhaps this question is better suited to the cross validation SE site, now that I think of it. The distinction is somewhat unclear to me... –  Frost Jun 24 at 12:36
4  
I think the question is very much fitting to this site, since it discusses a practical application of machine learning. btw, silly question, why so few photos of cats? Do they only come around for just five seconds? –  insys Jun 24 at 12:45
    
@insys, rumors about my vigilance with the soaker appears to have spread in the feline community. They tend not to linger like they used to. I guess that's a good thing w/r/t the actual objective of ridding my garden of cats, even though it complicates my preferred, more sophisticated solution. –  Frost Jun 24 at 19:54
2  
Seems like the obvious next step (after you get the cat detection working) is a raspberry pi controlled super soaker :-) –  Kryten Jun 24 at 20:56
1  

5 Answers 5

up vote 6 down vote accepted

You could simplify your problem significantly by using a motion/change detection approach. For example, you could compare each image/frame with one from an early time (e.g., a minute earlier), then only consider pixels that have changed since the earlier time. You could then extract the rectangular region of change and use that as the basis for your classification or anomaly detection.

Taking this type of approach can significantly simplify your classifier and reduce your false target rate because you can ignore anything that is not roughly the size of a cat (e.g., a person or bird). You would then use the extracted change regions that were not filtered out to form the training set for your classifier (or anomaly detector).

Just be sure to get your false target rate sufficiently low before mounting a laser turret to your feline intrusion detection system.

share|improve this answer
    
This is a nice idea for a controlled environment but I'm not sure of it's applicability in this case, since we are dealing with the natural environment where there is continuous change, i.e. change in weather, position of sun, plants and trees because of wind, seasons etc. I believe the region of change as you describe would grow close to the size of the whole image in any case. –  insys Jun 24 at 20:05
    
@insys - I see your point but I disagree - I believe it makes the detector more resilient to change. The time difference between relative frames should be small (~ seconds to a minute) so sun, season, weather should be negligible. I agree that wind will cause plants to move but the classification step can avoid those since their size/shape/color are different than a cat. Plus, using two frames at similar times enables normalizing pixel intensities to better handle varying illumination conditions (e.g., a cat on a sunny vs. cloudy day). –  bogatron Jun 24 at 20:55
    
Actually, I am more confused about your answer now that I read through your comment :) Perhaps I misunderstood, but if you actually use the "extracted change regions" to form your positive samples, as mentioned in your question, how do you even make sure they are cats? They could be anything. As such, your classification step would fail to detect anything but what is taught to detect – that is, changes of any kind. So it is actually repeating the job of the "change" detector. –  insys Jun 24 at 21:21
    
Furthermore, illumination conditions are definitely of concern, but, if I get your point right, it is unclear what two similar images, taken with a difference of 1 minute would offer towards normalising pixel intensities? –  insys Jun 24 at 21:22
    
The extracted regions can represent either positive or negative examples - they are what you would use to train the cat classifier. With regard to intensities, Suppose the classifier is trained from regions extracted primarily from sunny images. The classifier might then easily find cats with bright white fur but that won't work well later on a cloudy day (when the white fur isn't nearly as bright) or near dusk. Performing a normalization of the two images helps mitigate that problem (i.e., a pair of bright images and a pair of dim images would appear similar to the classifier). –  bogatron Jun 24 at 22:00

This is an interesting and also quite ambitious project :)

I am not sure anomaly detection (at least in the sense described in the course you followed) would be a very fitting algorithm in this case.

I would consider a more viable approach to be what has been discussed at the end of that course where a Photo OCR workflow was demonstrated.

The approach would consist of segmenting your image in smaller "blocks", and going through them one-by-one using a supervised learning algorithm and try to classify each block according to whether it contains a cat or not. If one block contains a cat, the alarm goes off. As a bonus, you get the position of the cat as well, so that you may think of incorporating some "automatic" response as a future step to your project.

The benefit here is that you will not have to train your algorithm using a dataset specific to your garden (which, as you mention is difficult to create), but you can use images of cats taken off the net (e.g. perhaps you can search for "cat on grass" or something), and perhaps patches of photos from your (or other) gardens. Therefore you don;t have to spend your time collecting photos from your camera, and you avoid the risk of having a very small (comparable) sample of positives (i.e. cats).

Now, of course how easy it is to build an accurate cat detector is another topic..

share|improve this answer
    
And what would happen if your block splits the cut into two or more slices? The blocking strategy is a very common approach, but when having a camera completely fixed to a certain position, motion detection is a better and less time-consuming approach, from my point of view. –  adesantos Jun 25 at 7:08
    
@adesantos – What you say may well be true, and for prediction differentiating between moving and non-moving parts has it's advantages. But for training, the way it is described by bogatron, it is unclear what benefits it brings to the table. Overall, my opinion is it adds complexity, which lengthens the debugging time significantly. The advantage of moving window is in it's simplicity. –  insys Jun 25 at 7:36
    
Btw, regarding the split that you mention, an obvious strategy is to let your windows overlap, so that split position does not affect your classifier. –  insys Jun 25 at 7:36
    
I would add to my proposal (motion detection) the use of SIFT algorithm with a cat texture. The SIFT method can also be used with that strategy of blocks, but in that case you will compare more blocks than require. Notice that a cat moves, but a tree or a bush not that much. –  adesantos Jun 25 at 9:06

The strategy of motion/change detection is certainly adequate, but I would add an extra operation. I would detect those regions that are more likely to be changed, for instance, the ladder seems a place where humans can be (also cats) and grass where dogs, cats or humans can be.

I would capture a map with size of the object and trajectory and with this I would create a cluster with the aim of detecting an object (with specific size within the image in terms of pixels) that moves with a certain speed and trajectory.

You can achieve this by using R or I would suggest OpenCV in order to detect movement and follow different objects.

share|improve this answer

OpenCV's background subtraction will find objects moving about your harden. After that you could use a classifier or shape analysis to differentiate between cats, people, trees and etc.

share|improve this answer

Is it a bird? Is it a cat? We have black-and-white cat-sized! magpies here. so that would fail.

First thing would be to exclude all areas that are green, cats are seldom green.

Then compare the rest to a reference image to remove static things like stones and stairs.

Detecting objects of a minimum size should be possible, but for a classification the resolution is too low. Could be also your neighbor testing his new remote controlled drone.

With two cameras you could do a 3d mapping of the objects and eliminate flying objects.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.