【问题标题】:rectangle for detection object with HOG+SVM Opencv使用 HOG+SVM Opencv 检测对象的矩形
【发布时间】:2016-02-02 11:41:28
【问题描述】:

我想使用矩形进行物体检测,但首先我想了解代码。这是一个示例代码:

vector<Rect> found, found_filtered;
    size_t i, j;

    hog.detectMultiScale(mGray, found, 0, Size(8,8), Size(32,32), 1.05, 2);


    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);
        }



    if(found.size()) {
            Rect r = found[0];
            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);
            LOGD("c : %d, r : %d",r.height,r.width);



         rectangle(mGray, r.tl(), r.br(), cv::Scalar(255,0,0), 3);
    }

所以,我想逐行理解这段代码:

if(found.size()) {
                Rect r = found[0];
                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);
                LOGD("c : %d, r : %d",r.height,r.width);

你怎么看?

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    看起来它是按如下方式缩小对象矩形(红色 - 原始检测,绿色 - 新矩形):

    r.x += cvRound(r.width*0.1); // move rectangle to right by 10% of width
    r.width = cvRound(r.width*0.8); // reduce rectangle width
    r.y += cvRound(r.height*0.07); // move rectangle down by 7% of width
    r.height = cvRound(r.height*0.8); // reduce rectangle width
    LOGD("c : %d, r : %d",r.height,r.width); // print coordinates of top left corner, width and height
    

    我认为这是因为当您训练检测器时,您会在对象周围传递带有一些背景的样本。所以当你用这种检测器检测物体时,矩形会比物体大很多。为了使矩形更具体,您可以按上述方法缩小它。

    【讨论】:

    • 为什么要减小矩形宽度和高度@akarsakov?那个图片链接是什么?
    • 为了使矩形尺寸更接近物体,因为检测器会输出带有物体周围背景的矩形。提供图片来说明此过程。
    • 您认为该代码对我完全有效吗@akarsakov?你能给我一个链接来说明这个过程吗?未找到该链接
    • @FranksyeSipangkar 你应该做实验。如果矩形的大小对您来说足够好,请按原样使用。否则,只需删除这行代码(来自r.x += cvRound(r.width*0.1);)。
    • 感谢您的建议。这对我有用。我有一个问题要问您,您知道使用 HOG+SVM 进行自定义对象检测的准确率吗? @akarsakov
    猜你喜欢
    • 2011-11-30
    • 2016-05-01
    • 2012-06-01
    • 2023-03-13
    • 1970-01-01
    • 2021-09-06
    • 2012-10-18
    • 2019-01-02
    • 2018-05-03
    相关资源
    最近更新 更多