gpu :: resize的问题

时间:2015-06-28 21:58:08

标签: c++ opencv pattern-recognition

我正在尝试在GPU上计算不同级别的HOG功能,然后我将每个级别的功能保存到yml文件中。以下是我正在使用的功能。

void App::run()
{
    unsigned int count = 0;
    FileStorage fs;
    running = true;

    int width = 640;
    int height = 480;

    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();

            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);

                //double scale = 1.05;
                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);

                cout<<"Levels "<<levels<<endl;

                if(width < win_size.width || height < win_size.height)
            break;

            resize(img,img_new,Size(width,height));
            scale *= scale;
                }

                cout<<count<<endl;
                count++;
            }

            hogWorkEnd();
            fs.release();
          }
           else  running = false;
       }
}

对于第一个图像,它正确地计算所有级别的HOG特征,但对于下一个图像,它采用旧的宽度和高度值,在这种情况下,它会打破以下循环。

if(width < win_size.width || height < win_size.height)
break;

有人可以指出我的错误。我试图调试,但遗憾的是还没有成功。

1 个答案:

答案 0 :(得分:0)

每个图像的HOG特征计算取以下三个参数的旧值 1.宽度
2.高度
3.比例

当它为下一个图像计算HOG特征时,它会立即打破循环。常见的编程错误。