简体   繁体   English

OpenCV 3 HOG 检测信心?

[英]OpenCV 3 HOG Detection confidence?

I am using the OpenCV 3 HOG people detector to detect people moving in front of my laptops web cam.我正在使用 OpenCV 3 HOG 人员检测器来检测在我的笔记本电脑网络摄像头前移动的人。 The detection part works sort of fine but I would like to obtain the confidence from the HOG classifier, which I think should be possible.检测部分工作得很好,但我想从 HOG 分类器中获得置信度,我认为这应该是可能的。

I use the following code to obtain the bounding boxes for the detected objects:我使用以下代码获取检测到的对象的边界框:

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

According to the Intellisense tip it should be possible to extract the confidence using:根据 Intellisense 提示,应该可以使用以下方法提取置信度:

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

But I am not sure how to declare and initialize the *confidence variable, can you please help me?但我不确定如何声明和初始化 *confidence 变量,你能帮我吗?

You can take a look at official OpenCV documentation , it declares this overload of detectMultiScale function ( CPU implementation):您可以查看官方 OpenCV 文档,它声明了 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

and for GPUGPU

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

So you can simply call it ( CPU mode):所以你可以简单地调用它( CPU模式):

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

or ( GPU implementation):或( GPU实现):

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

And if it will not work, OpenCV will throw an exception.如果它不起作用,OpenCV 将抛出异常。 You can display it like this:你可以这样显示:

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

After that you can solve the problem之后你就可以解决问题了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM