每个图像的HOG特征计算采用以下三个参数的旧值
1.宽度
2.身高
3.规模
我正在尝试计算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 %dn", 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.宽度
2.身高
3.规模
当它为下一个图像计算HOG特征时,它会立即打破循环。一个常见的编程错误。