2016-10-13 69 views
2

我使用OpenCV 3 HOG人員探測器來探測在我的筆記本電腦網絡攝像頭前移動的人員。檢測部分的工作很好,但我想從HOG分類器中獲得信心,我認爲這應該是可能的。OpenCV 3 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

你可以看看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; 
} 

之後,你就可以解決問題

+0

謝謝,但我得到以下異常拋出: –

+0

異常在HOG_GPU.exe在0x00007FFA8C537788拋出:微軟C++異常:CV: :內存位置0x0000005431F0E690處出現異常。 HOG_GPU.exe中的0x00007FFA8C537788處未處理的異常:Microsoft C++異常:內存位置0x0000005431F0E690處的cv :: Exception異常。 –

+0

@ErikS,如果您有例外 - 向我們顯示其文本 – Evgeniy