[英]OpenCV 3 HOG Detection confidence?
我正在使用 OpenCV 3 HOG 人員檢測器來檢測在我的筆記本電腦網絡攝像頭前移動的人。 檢測部分工作得很好,但我想從 HOG 分類器中獲得置信度,我認為這應該是可能的。
我使用以下代碼獲取檢測到的對象的邊界框:
std::vector< cv::Rect> found_locations_rect;
d_hog->detectMultiScale(rGpuImg, found_locations_rect);
根據 Intellisense 提示,應該可以使用以下方法提取置信度:
void detectMultiScale(cv::InputArray img, std::vector<cv::Rect> &found_locations, std::vector<double> *confidence = (std::vector<double> *)0);
但我不確定如何聲明和初始化 *confidence 變量,你能幫我嗎?
您可以查看官方 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
和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;
}
之后你就可以解決問題了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.