OpenCV 3 HOG检测信心?

时间:2016-10-13 08:10:24

标签: c++ opencv

我正在使用OpenCV 3 HOG人物检测器来检测在我的笔记本电脑网络摄像头前移动的人。检测部分工作正常,但我想获得HOG分类器的信心,我认为应该是可能的。

我使用以下代码获取检测到的对象的边界框:

std::vector< cv::Rect> found_locations_rect;
d_hog->detectMultiScale(rGpuImg, found_locations_rect);

根据智能感知提示,应该可以使用以下方法提取信心:

void detectMultiScale(cv::InputArray img, std::vector<cv::Rect> &found_locations, std::vector<double> *confidence = (std::vector<double> *)0);

但我不知道如何声明和初始化*置信变量,你能帮我吗?

1 个答案:

答案 0 :(得分:1)

您可以查看official OpenCV documentation,它声明了detectMultiScale函数的重载( CPU 实现):

virtual void cv::HOGDescriptor::detectMultiScale    (   InputArray  img,
std::vector< Rect > &   foundLocations,
std::vector< double > &     foundWeights,
double  hitThreshold = 0,
Size    winStride = Size(),
Size    padding = Size(),
double  scale = 1.05,
double  finalThreshold = 2.0,
bool    useMeanshiftGrouping = false 
)       const

for GPU

virtual void cv::cuda::HOG::detectMultiScale    (   InputArray  img,
std::vector< Rect > &   found_locations,
std::vector< double > *     confidences = NULL 
)   

所以你可以简单地调用它( CPU 模式):

std::vector< cv::Rect> found_locations_rect;
std::vector<double> found_weights;
d_hog->detectMultiScale(mat, found_locations_rect, found_weights);

或( GPU 实施):

std::vector< cv::Rect> found_locations_rect;
std::vector<double> confidences;
d_hog->detectMultiScale(rGpuImg, found_locations_rect, &confidences);

如果它不起作用,OpenCV将抛出异常。您可以这样显示:

try
{
    std::vector< cv::Rect> found_locations_rect;
    std::vector<double> confidences;
    d_hog->detectMultiScale(rGpuImg, found_locations_rect, &confidences);
}
catch(const std::exception& e)
{
    std::cout << e.what() << std::endl;
}

之后你可以解决问题