[英]OpenCV HOG feature data layout?
我正在使用OpenCV的CPU版本的“定向直方圖”( HOG )。 我正在使用32x32圖像,其中包含4x4單元格,4x4塊,塊之間沒有重疊以及15個方向箱。 OpenCV的HOGDescriptor
為我提供了長度為960的一維特征向量。這是有道理的,因為(32 * 32像素)*(15個方向)/(4 * 4個像元)= 960。
但是,我不確定這960個數字在內存中的布局方式。 我的猜測是這樣的:
vector<float> descriptorsValues =
[15 bins for cell 0, 0]
[15 bins for cell 0, 1]
...
[15 bins for cell 0, 7]
....
[15 bins for cell 7, 0]
[15 bins for cell 7, 1]
...
[15 bins for cell 7, 7]
當然,這是一個將2D問題扁平化為1D的問題,因此實際上看起來像這樣:
[cell 0, 0] [cell 0, 1] ... [cell 7, 0] ... [cell 7, 7]
這是我的示例代碼:
using namespace cv;
//32x32 image, 4x4 blocks, 4x4 cells, 4x4 blockStride
vector<float> hogExample(cv::Mat img)
{
img = img.rowRange(0, 32).colRange(0,32); //trim image to 32x32
bool gamma_corr = true;
cv::Size win_size(img.rows, img.cols); //using just one window
int c = 4;
cv::Size block_size(c,c);
cv::Size block_stride(c,c); //no overlapping blocks
cv::Size cell_size(c,c);
int nOri = 15; //number of orientation bins
cv::HOGDescriptor d(win_size, block_size, block_stride, cell_size, nOri, 1, -1,
cv::HOGDescriptor::L2Hys, 0.2, gamma_corr, cv::HOGDescriptor::DEFAULT_NLEVELS);
vector<float> descriptorsValues;
vector<cv::Point> locations;
d.compute(img, descriptorsValues, cv::Size(0,0), cv::Size(0,0), locations);
printf("descriptorsValues.size() = %d \n", descriptorsValues.size()); //prints 960
return descriptorsValues;
}
相關資源: 這篇StackOverflow帖子和本教程幫助我開始使用OpenCV HOGDescriptor。
我相信您有正確的主意。
它在其原始論文《 用於人類檢測的定向梯度直方圖》 (第2頁)中說
探測器窗口上鋪有重疊塊的網格,其中提取了定向梯度特征向量直方圖。 [...]
daccess-ods.un.org daccess-ods.un.org用HOG描述符的密集(實際上是重疊的)網格平鋪檢測窗口,並使用組合特征向量
所有它講到被平鋪在一起他們。 盡管沒有介紹有關如何將它們精確平鋪在一起的詳細信息。 我猜這里不應該發生任何幻想的事情(否則他們會談論它),即只是定期將它們串聯起來(從左到右,從上到下)。
畢竟,這是合理且最簡單的數據布局方式。
編輯:如果您查看人們如何訪問和可視化數據,將使自己更加信服。
for (int blockx=0; blockx<blocks_in_x_dir; blockx++)
{
for (int blocky=0; blocky<blocks_in_y_dir; blocky++)
{
for (int cellNr=0; cellNr<4; cellNr++)
{
for (int bin=0; bin<gradientBinSize; bin++)
{
float gradientStrength = descriptorValues[ descriptorDataIdx ];
descriptorDataIdx++;
// ... ...
} // for (all bins)
} // for (all cells)
} // for (all block x pos)
} // for (all block y pos)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.