如何跟踪猪的描述符检测到的人

时间:2016-08-25 12:50:42

标签: c++ opencv computer-vision opencv3.0

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

using namespace std;
using namespace cv;

int main ()
{
VideoCapture cap("/opencv/images/people.avi");
if (!cap.isOpened())
    return -1;

Mat img;
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

namedWindow("video capture", CV_WINDOW_AUTOSIZE);
while (true)
{
    cap >> img;
    if (!img.data)
        continue;

    vector<Rect> found, found_filtered;
    hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);

    size_t i, j;
    for (i=0; i<found.size(); i++)
    {

        Rect r = found[i];
        for (j=0; j<found.size(); j++)
            if (j!=i && (r & found[j])==r)
                break;
        if (j==found.size())
            found_filtered.push_back(r);
    }
    for (i=0; i<found_filtered.size(); i++)
    {
                        Rect r = found_filtered[i];
                        Point textOrg(r.x,r.y);
                        r.x += cvRound(r.width*0.1);
                        r.width = cvRound(r.width*0.8);
                        r.y += cvRound(r.height*0.07);
                        r.height = cvRound(r.height*0.8);
                        rectangle(img, r.tl(), r.br(), Scalar(0,255,0), 3);
                        putText(img, "human", textOrg,
                                        FONT_HERSHEY_COMPLEX_SMALL, 0.8, Scalar::all(000), 1, CV_AA);

}
    imshow("video capture", img);
    if (waitKey(20) >= 0)
    {  break;}
}

return 0;
}

以上代码可用于使用hog检测每个帧中的人。但是我想跟踪这些人的动作识别。我希望使用密集的光流进行动作识别。我可以使用描述符进行跟踪,还是有其他好的方法。

0 个答案:

没有答案