Ask Your Question
1

Detect cattle in drone video footage

asked 2015-09-17 22:47:30 -0600

Scott gravatar image

updated 2015-09-25 14:01:13 -0600

I’m looking at using OpenCV to detect cattle within footage taken from a drone.

Every time I get to the point of making a decision on what technique I should use I either read something contradictory that indicates that it might be a bad choice or I read about some other technique which seems more suitable.
My current feeling is that I should use a LBP Cascade Classifier, but every time I learn something new about it I realise that there’s dozens of other things I don’t know about it or don’t understand fully. And, case in point, just seconds ago I read that HAAR and LBP might not be as suitable for non-rigid objects as some other techniques.
So, while I realise that there will be no ‘right’ answer or silver bullet, I’m looking for some guidance to narrow down the set of techniques I that I should be looking into more deeply.

My initial requirement is to be able to process footage taken from a drone that has crisscrossed a paddock (field) and identify the specific parts of the footage that contain cattle. This information can then be used to create index points (chapters) in the video so that skipping to the next ‘interesting’ piece of footage is simple. Ideally I'd also be able to display an identifying box around the detected cattle.
Initially we can assume that there will not be any other animals, such as horses or sheep, present in the footage or if there are other animals we don’t mind them being detected as well. In an ideal world it’d be nice to be able to tell the difference between a horse and a cow, but for now that’s not a requirement.
The footage of the paddocks will generally be free of other cattle shaped objects, but it will contain trees, logs and rocky outcrops. There will also possibly be sheds, houses, fences and vehicles contained within the footage as well as varying shadows and different shades of grass you would expect to find in such footage.

Most questions/answers that I see about detecting animals (or non-uniform objects) in video footage are about fixed surveillance type camera footage where the background doesn’t change except for gradual lighting changes and most could be solved with simple motion detection. Obviously footage taken from a continually moving camera on a drone will have different problems to content with. The background will be constantly changing and also, because of the camera movement, cattle will not always be placed in one particular area of the frame, nor will they ever track along the same/similar path. Another issue is that I need to identify “cattle”, not “a cow that has has been nicely framed for a picture". Cattle move about in groups and the footage will rarely contain a full clean image of any individual animal, rather there will be animals obscuring each other and animals could be at ... (more)

edit retag flag offensive close merge delete

Comments

2

you could try the LatentSVMDetector in opencv2.4 (or its dpm successor in 3.0) , which has a pretrained cow detector, but again, it was trained on front/side view from the ground, not for top view from a drone.

berak gravatar imageberak ( 2015-09-18 01:08:29 -0600 )edit
3

oh, and as always, - an example image would be quite helpful !

berak gravatar imageberak ( 2015-09-18 01:10:44 -0600 )edit
1

I still did not find a train for that detector, I shall go to Matlab and train it there, and it is a little complex to read it like that ad make my data in the wanted format... :(

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-09-18 08:17:29 -0600 )edit

^^ heroic attempt !

berak gravatar imageberak ( 2015-09-19 02:39:08 -0600 )edit
1

@berak thanks for the tip on the LatentSVMDetector and DPM. The LatentSVMDetector seems like it might be pre-trained (or comes with one trained model). Information on the DPM is pretty thin on the ground. Looks like the LatentSVMDetector can only be trained/retrained with Matlab on Linux, which is disappointing. No idea about the DPM but I'm guessing the training options will be the same or worse.

Scott gravatar imageScott ( 2015-09-21 02:06:27 -0600 )edit
1

@berak I've edited question to include link to video footage which is much more relevant than any individual example image could be.

Scott gravatar imageScott ( 2015-09-21 02:14:34 -0600 )edit
1

@Scott, nice, but i won't download a 75mb video ;(

"I'm guessing the training options will be the same or worse." - i'm afraid, you're spot-on here ;(

berak gravatar imageberak ( 2015-09-21 02:28:18 -0600 )edit
1

pssst @berak, combine your remarks into an answer? ;)

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-22 03:15:02 -0600 )edit

1 answer

Sort by » oldest newest most voted
9

answered 2015-09-22 01:04:52 -0600

berak gravatar image

updated 2015-09-24 22:41:30 -0600

i made a quick try (dpm) with your image, results are so-la-la ;(

wget --no-check-certificate https://github.com/Itseez/opencv_extra/raw/master/testdata/cv/dpm/VOC2007_Cascade/cow.xml

image description

and for this i already had to crop it to a small part (low mem here) and upscale by a factor of 2

#include <opencv2/dpm.hpp>
#include <opencv2/opencv.hpp>

#include <iostream>

using namespace cv;
using namespace cv::dpm;
using namespace std;

int main( int argc, char** argv )
{
    // you can load/detect several cascades at once.

    vector<string> models;
    vector<string> names;
    //names.push_back("car");
    //models.push_back("car.xml");
    names.push_back("cow");
    models.push_back("cow.xml");

    cv::Ptr<DPMDetector> detector = DPMDetector::create(models,names);

    Mat frame = imread("cow.png");
    resize(frame,frame,Size(),2,2);
    namedWindow("DPM Cascade Detection", 1);   

    double t = (double) getTickCount();

    // detection
    vector<DPMDetector::ObjectDetection> ds;
    detector->detect(frame.clone(), ds); // it somehow eats the image ;(

    t = ((double) getTickCount() - t)/getTickFrequency();//elapsed time
    cerr << "dpm took " << t << " seconds" << endl;

    for (unsigned int i = 0; i < ds.size(); i++)
    {
        int id = ds[i].classID;
        cerr << names[id] << "\t" << ds[i].score << "\t" << ds[i].rect << endl;
        //
        // there's a "<ScoreThreshold>" tag hidden in the xml !
        //
        //if (ds[i].score < -0.95)
        //    continue;
        rectangle(frame, ds[i].rect, Scalar(0, 255, 255), 1);
    }

    imshow("DPM Cascade Detection", frame);
    imwrite("cow_det.png", frame);

    waitKey(0);

    return 0;
}
edit flag offensive delete link more

Comments

3

Source code and everything, you've gone above and beyond @berak
Thanks.

Scott gravatar imageScott ( 2015-09-24 00:12:54 -0600 )edit

Hi, what's "dpm.hpp" ? it doesn't seem to exist in my OpenCV include folder :(

mubb gravatar imagemubb ( 2015-10-14 08:42:13 -0600 )edit
1

hi @mubb, you need opencv3 and opencv_contrib for this

berak gravatar imageberak ( 2015-10-14 08:59:09 -0600 )edit

@break Can this file (cow.xml) be used for the LatentSVMDetector (opencv2.4) instead of DPMDetector (opencv3.0)?

AlexB gravatar imageAlexB ( 2015-10-14 17:23:40 -0600 )edit

@AlexB - i do not think so. you have to take care to use the 2.4 branch : https://github.com/Itseez/opencv_extr...

berak gravatar imageberak ( 2015-10-14 23:54:58 -0600 )edit

oh no, not openCV3 again ! i'll try it on the only computer i got it to work on then !

mubb gravatar imagemubb ( 2015-10-15 09:48:20 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2015-09-17 22:47:30 -0600

Seen: 3,363 times

Last updated: Sep 24 '15