【问题标题】:Human Detection Using HOG Descriptor使用 HOG 描述符进行人体检测
【发布时间】:2016-09-29 14:07:40
【问题描述】:

我是使用 HOG 检测器检测路上的人的新手,我已经编写了代码并尝试运行它,但它总是在这一行出现错误:“hog.setSVMDetector(HOGDescriptor: :getDefaultPeopleDetector());"这一行,谁能告诉我我的代码有什么问题?

    #include < stdio.h>
    #include < iostream>
    #include < opencv2\opencv.hpp>
    #include < opencv2/core/core.hpp>
    #include < opencv2/highgui/highgui.hpp>
    #include < opencv2/video/background_segm.hpp>
    #include <opencv2/imgproc.hpp>
    #include <opencv2/objdetect.hpp>
    #include <peopledetect.cpp>

    using namespace cv;
    using namespace std;

    int main(int argc, const char * argv[])
    {
        VideoCapture cap(0);
        cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
        cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);

        if (!cap.isOpened())
            return -1;

        Mat img;
        namedWindow("opencv", CV_WINDOW_AUTOSIZE);
        HOGDescriptor hog;
        hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

        while (true)
        {
            cap >> img;
            if (img.empty())
                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];
                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);
            }

            imshow("opencv", img);
            waitKey(1);
        }
        return 0;
    }

【问题讨论】:

  • 有什么特别的错误吗?系统着火了?鼻腔律师?
  • 它说“异常情况:0xC0000005:读取 0xFFFFFFFFFFFF 违规”
  • 我不知道我是否需要做任何进一步的步骤,例如是否需要首先初始化“getDefaultPeopleDetector()”或什么?
  • #include &lt;peopledetect.cpp&gt; ?真的吗?
  • 对不起,我只是不知道该怎么做,我看到 getDefaultPeopleDetector() 是由 peopledetect.cpp 编码的,所以我将其包含在内...

标签: c++ opencv object-detection descriptor


【解决方案1】:

一般来说,您不应该在 C++ 程序中包含 .cpp 文件。有 .h 和 .hpp 头文件。

现在,对于您的特定问题,如果我们谈论的是同一个 peopledetect.cpp,那么您想要的函数没有在那里定义,而是在包含在那里的头文件中......您可能已经有了正确的头文件(objdetect.hpp ) 所以只需删除#include &lt;peopledetect.cpp&gt;

【讨论】:

  • 但是删除cpp文件后,错误依旧,是我输入格式有问题吗?
  • 是的,完全一样
  • 使用getDefaultPeopleDetector(),我根本不需要训练任何描述符好吗?
  • 我想您已经知道this page,因为您在那里复制了代码并添加了一些错误。原始代码是否适用于您的设置?
  • 嗯,唯一的区别是我用的是opencv 2.4.13而不是2.3,而且输入的是不是来自网络摄像头的视频
猜你喜欢
  • 2014-07-05
  • 2016-05-03
  • 2019-12-03
  • 2012-08-01
  • 2015-08-12
  • 2019-08-19
  • 2017-01-14
  • 2016-05-01
  • 2014-11-26
相关资源
最近更新 更多