[英]HOG features for object detection using GPU in OpenCV
In my project I am calculating HOG features on GPU for different levels in the same image. 在我的项目中,我正在计算同一图像中不同级别的GPU上的HOG功能。 My aim is to detect the following objects.
我的目的是检测以下物体。
1. Truck 1.卡车
2. Car 2.车
3. Person 3.人
Most important question is the selection of window size in case of multi class object detector. 最重要的问题是在多类目标检测器的情况下窗口大小的选择。 This post provide a very good base but it does not provide an answer for the selection of window size in case of multi class feature.
这篇文章提供了很好的基础,但是在多类功能的情况下,并没有为选择窗口大小提供答案。
To solve this problem I calculated the HOG features of each positive image at different levels/resolution keeping the window size(48*96) same but the file for each image is around 600 MB which is too large. 为了解决这个问题,我计算了每个正图像在不同级别/分辨率下的HOG特征,并保持窗口大小(48 * 96)不变,但是每个图像的文件大约为600 MB,这太大了。
Please let me know how to select the window size, block size and cell size in case of multi class object detection. 请让我知道在多类对象检测的情况下如何选择窗口大小,块大小和单元格大小。 Here is my code that I used to calculate the HOG features.
这是我用来计算HOG功能的代码。
void App::run()
{
unsigned int count = 1;
FileStorage fs;
running = true;
//int width;
//int height;
Size win_size(args.win_width, args.win_width * 2);
Size win_stride(args.win_stride_width, args.win_stride_height);
cv::gpu::HOGDescriptor gpu_hog(win_size, Size(16, 16), Size(8, 8), Size(8, 8), 9,
cv::gpu::HOGDescriptor::DEFAULT_WIN_SIGMA, 0.2, gamma_corr,
cv::gpu::HOGDescriptor::DEFAULT_NLEVELS);
VideoCapture vc("/home/ubuntu/Desktop/getdescriptor/images/image%d.jpg");
Mat frame;
Mat Left;
Mat img_aux, img, img_to_show, img_new;
cv::Mat temp;
gpu::GpuMat gpu_img, descriptors, new_img;
char cbuff[20];
while (running)
{
vc.read(frame);
if (!frame.empty())
{
workBegin();
width = frame.rows;
height = frame.cols;
sprintf (cbuff, "%04d", count);
// Change format of the image
if (make_gray) cvtColor(frame, img_aux, CV_BGR2GRAY);
else if (use_gpu) cvtColor(frame, img_aux, CV_BGR2BGRA);
else Left.copyTo(img_aux);
// Resize image
if (args.resize_src) resize(img_aux, img, Size(args.width, args.height));
else img = img_aux;
img_to_show = img;
gpu_hog.nlevels = nlevels;
hogWorkBegin();
if (use_gpu)
{
gpu_img.upload(img);
new_img.upload(img_new);
fs.open(cbuff, FileStorage::WRITE);
for(int levels = 0; levels < nlevels; levels++)
{
gpu_hog.getDescriptors(gpu_img, win_stride, descriptors, cv::gpu::HOGDescriptor::DESCR_FORMAT_ROW_BY_ROW);
descriptors.download(temp);
//printf("size %d %d\n", temp.rows, temp.cols);
fs <<"level" << levels;
fs << "features" << temp;
cout<<"("<<width<<","<<height<<")"<<endl;
width = round(width/scale);
height = round(height/scale);
if( width < win_size.width || height < win_size.height )
break;
cout<<"Levels "<<levels<<endl;
resize(img,img_new,Size(width,height));
scale *= scale;
}
cout<<count<< " Image feature calculated !"<<endl;
count++;
//width = 640; height = 480;
scale = 1.05;
}
hogWorkEnd();
fs.release();
}
else running = false;
}
}
The window size should be chosen, st the object(s) you want to detect fit into the window. 应该选择窗口大小,要检测的对象适合窗口大小。 If you want to have different window sizes for different types this might become tricky.
如果要为不同类型使用不同的窗口大小,这可能会变得棘手。
Usually what you do is the following 通常您要做的是以下
If you want to use differently sized detection windows you will get feature vectors of different size (by nature of the HoG features). 如果要使用不同大小的检测窗口,则将获得不同大小的特征向量(根据HoG特征的性质)。 The tricky thing is, that in the testing phase you have to use as many sliding windows as object types you use.
棘手的是,在测试阶段,您必须使用与所使用的对象类型一样多的滑动窗口。 This would definitely work, but you have to process each testing image several times leading to higher processing time)
这肯定可以,但是您必须多次处理每个测试图像,从而导致处理时间更长)
To answer your question of the sizes: There is no value I can give you, it always depends on your images. 要回答您的尺寸问题:我不能给您任何价值,它始终取决于您的图像。 Using an image pyramid as you mentioned above is a good way to deal with differently scaled objects.
如上所述,使用图像金字塔是处理不同比例对象的好方法。
Sample code for visualization of HoG features can be found here . 可在此处找到可视化HoG功能的示例代码。 This also helps understand how the feature vectors look like.
这也有助于了解特征向量的外观。
EDIT: Found out the hard way, that only cv::Size(8,8)
is allowed for cell size. 编辑:发现困难的方法,只有
cv::Size(8,8)
允许用于单元格大小。 See documentation . 请参阅文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.