OpenCV: Detecting cat with specific color. Trivial?
Asked Answered
K

1

9

I have a problem with my cat being bullied by a nabouring cat to the extent that the cat enters our house in the summer and eat our cats food and sleeps in our furniture.

My cat is gray and the problem cat is brown.

I would like to make an alert system using a WiFi action cam and OpenCV detection on a Linux box, but I don't do much coding anymore.

So my question is. Is this a trivial task using standard OpenCV modules?

Or would it require a large amount of original code?

I know that there is OpenCV Cascade Classifier, but have never used it.

Kind Regards

Jacob

Keiko answered 11/5, 2016 at 9:5 Comment(6)
Upvoting because you made me smileMezzotint
i like the idea if you are serious. if you provide some more information about your project i will try to do some suggestions.Rowena
@Rowena I'm not sure what else to tell. The plan is to have a stationary camera mounted above my front door which sends a live video stream to a Linux box and then have that box detect a specific cat based on all round color, or any cat that is not mine.Keiko
@user3866319 i will try to improve my answer according to your feedbacks. i hope it will be helpful.Rowena
@Rowena I managed to compile your example and found that even though it takes a very long time it does detect "iconic" cat images, but when ever I use an image with more different objects and more "difficult" cat stances, I get either no green rects, or rects all over the place. How can I train the classifier?Keiko
I would start by a much easier method than training a cascade of classifiers. Training a cascade of classifier is a hard and time consuming task. It is also very sensitive to the point of view. Instead, I would try first to use background substraction in order to detect motion and then HSV color detection.Newsreel
R
1

it is very initial answer just to show a way to start your project.

you can try to find trained classifiers for cats. for example i found this and tested some cat images with the code below.

#include <iostream>

#include "opencv2/highgui.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/imgproc.hpp"

using namespace std;
using namespace cv;

int main( int argc, const char** argv )
{
    if (argc < 3)
    {
    cerr << "usage:\n" << argv[0] << " <image_file_name> <model_file_name>" << endl;
    return 0;
    }

    // Read in the input arguments
    string model = argv[2];

    CascadeClassifier detector(model);
    if(detector.empty())
    {
        cerr << "The model could not be loaded." << endl;
    }

    Mat current_image, grayscale;

    // Read in image and perform preprocessing
    current_image = imread(argv[1]);
    cvtColor(current_image, grayscale, CV_BGR2GRAY);

    vector<Rect> objects;
    detector.detectMultiScale(grayscale, objects, 1.05, 1);

    for(int i = 0; i < objects.size(); i++)
    {
        rectangle(current_image, objects[i], Scalar(0, 255, 0),2);
    }

    imshow("result",current_image);
    waitKey();
    return 0;
}

some result images i get

enter image description here enter image description here enter image description here

when you find a satisfactory classifier you can use it with video frames and you can do filtering on detected cats with their colors.

also you can take a look at

cat detection using latent SVM in opencv

Black Cat Detector (no idea if it works)

Rowena answered 11/5, 2016 at 21:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.