繁体   English   中英

HOG功能,用于在OpenCV中使用GPU进行对象检测

[英]HOG features for object detection using GPU in OpenCV

在我的项目中,我正在计算同一图像中不同级别的GPU上的HOG功能。 我的目的是检测以下物体。
1.卡车
2.车
3.人
重要的问题是在多类目标检测器的情况下窗口大小的选择。 这篇文章提供了很好的基础,但是在多类功能的情况下,并没有为选择窗口大小提供答案。
为了解决这个问题,我计算了每个正图像在不同级别/分辨率下的HOG特征,并保持窗口大小(48 * 96)不变,但是每个图像的文件大约为600 MB,这太大了。
请让我知道在多类对象检测的情况下如何选择窗口大小,块大小和单元格大小。 这是我用来计算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;
       }
} 

应该选择窗口大小,要检测的对象适合窗口大小。 如果要为不同类型使用不同的窗口大小,这可能会变得棘手。

通常您要做的是以下

  1. 获取每种对象类型的训练数据,并使用在对象已知位置提取的特征来训练[对象类型数量]许多模型。
  2. 然后,您获取每个测试图像,并使用滑动窗口方法在每个位置提取特征。 然后将这些功能与每个模型进行比较。 如果其中一个模型的得分高于某个阈值,则说明已找到该对象。 如果一个以上模型的得分高于阈值,则只需取一个得分最高的模型即可。

如果要使用不同大小的检测窗口,则将获得不同大小的特征向量(根据HoG特征的性质)。 棘手的是,在测试阶段,您必须使用与所使用的对象类型一样多的滑动窗口。 这肯定可以,但是您必须多次处理每个测试图像,从而导致处理时间更长)

要回答您的尺寸问题:我不能给您任何价值,它始终取决于您的图像。 如上所述,使用图像金字塔是处理不同比例对象的好方法。

  • 窗口大小:整个对象应适合; 必须被块大小整除
  • 块大小必须被单元大小整除

可在此处找到可视化HoG功能的示例代码。 这也有助于了解特征向量的外观。

编辑:发现困难的方法,只有cv::Size(8,8)允许用于单元格大小。 请参阅文档

暂无
暂无

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

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