Haarcascading XML无法正常运行

时间:2017-11-01 10:53:23

标签: c++ xml opencv3.0

我对OpenCV和级联培训很陌生。我确实训练了一个级联来识别“跑步”动作。我使用Haar-like和LBP。对于像哈尔一样,我使用了1181个正面图像和3866个负面图像和12个阶段。对于LBP,我使用了2426张正面图像和1031张负面图像以及12张分段图像。

关注后,您可以看到每个人的屏幕截图。

haar-like cascading

LBP cascading

等待训练完成一段时间后(每个训练大约3-4个小时),我将能够从AdaBoost图表分类器创建xml文件。 问题是,当我在我的代码上使用它们来查看它们是如何工作时,它们不会识别任何明显的运行动作!代码是用C ++和OpenCV 3.3编写的。

有没有人知道为什么训练后我的级联xml文件无法正常工作?

C ++代码如下:

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
    //open from file
    VideoCapture video("../data/videos/people_activity/run/run2.mp4");
    Mat img;
    Mat frmg;

    // Load cascate classifier placed in sulution folder
    CascadeClassifier bodydetector, rundetector;
    string bodycascadeName = "haarcascade_fullbody.xml";
    string runcascadeName = "lbpcascade_run.xml";
    bool bodyloaded = bodydetector.load(bodycascadeName);
    bool runloaded = rundetector.load(runcascadeName);


    // Parameters of detectMultiscale Cascade Classifier
    int groundThreshold = 1;
    double scaleStep = 1.1;
    Size minimalObjectSize(40, 40);
    Size maximalObjectSize(200, 200);



    // Vector of returned bodies and run
    std::vector<Rect> bodyfound, runmotion;

    while (video.read(img))
    {

        // Image from video read and store to Mat
        video >> img;

        if (img.rows == 0)//end of video
            break;


        // Convert input to greyscale 
        Mat image_grey;
        cvtColor(img, image_grey, CV_BGR2GRAY);

        bodyfound.clear();



        // Detect bodies
        bodydetector.detectMultiScale(image_grey, bodyfound, scaleStep, groundThreshold, 0 | 2, minimalObjectSize, maximalObjectSize);

        for (size_t k = 0; k < bodyfound.size(); k++)
        {


            //draw a rectangle with red color around it
            rectangle(img, bodyfound[k].br(), bodyfound[k].tl(), Scalar(0, 0, 0), 1, 8, 0);

            Mat bodyROI = img(bodyfound[k]);

            //Detect running for bodies if there is any!
            rundetector.detectMultiScale(bodyROI, runmotion, scaleStep, groundThreshold, 0 | 2, minimalObjectSize, maximalObjectSize);

            //if any were found!
            if (runmotion.size() > 0) {
                for (size_t i = 0; i < runmotion.size(); i++)
                {
                    //draw a rectangle with red color around it
                    rectangle(img, runmotion[i].br(), runmotion[i].tl(), Scalar(80, 0, 255), 1, 8, 0);
                }
            }
        }

        imshow("result", img);

        int c = waitKey(10);
        if ((char)c == 27) { break; } // escape

    }
    return 0;
}

0 个答案:

没有答案