Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Different results of gpu::HOGDescriptor and cv::HOGDescriptor

Hi,

we evaluate the performance improvement of the GPU implementation of the HOGDescriptor against the CPU implementation. During the tests, we compared the computed Descriptors of the GPU and the CPU implementation and saw that they are different. Why the Descriptors are different? Is this a bug?

The following code show our test application. We use the default people detector with default parameters on an frame from the OpenCV example video. The OpenCV version is opencv-2.4.10 and CUDA 6.5. The descriptor was computed at Rect(130, 80, 64, 128).

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/gpu/gpu.hpp>

using namespace std;
using namespace cv;

int main()
{
    //load image and upload to gpu
    Mat img(imread("frame_7.png", CV_LOAD_IMAGE_GRAYSCALE), Rect(130, 80, 64, 128));
    gpu::GpuMat gpu_img; gpu_img.upload(img);

    //initialize detector and HOGDescriptor
    vector<float> detector = HOGDescriptor::getDefaultPeopleDetector();
    gpu::HOGDescriptor gpu_hog(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8),9);
    HOGDescriptor cpu_hog(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9);
    gpu_hog.setSVMDetector(detector); cpu_hog.setSVMDetector(detector);

    //get descriptor vector -- cpu
    vector<float> cpu_descriptor, gpu_descriptor_vec;
    cpu_hog.compute(img, cpu_descriptor, Size(8, 8), Size(0, 0));

    //get descriptor vector -- gpu
    gpu::GpuMat gpu_descriptor_temp;
    gpu_hog.getDescriptors(gpu_img, Size(8, 8), gpu_descriptor_temp);
    Mat gpu_descriptor(gpu_descriptor_temp);
    gpu_descriptor.copyTo(gpu_descriptor_vec);

    //compare cpu_descriptor <--> gpu_descriptor
    for(int i=0;i<cpu_descriptor.size();i++){
        cout << i << " : " << cpu_descriptor[i] << " <--> " << gpu_descriptor_vec[i] << endl;
    }
    return 0;
}

Here is the test frame.

image description

If we visualize the descriptors with the method from here. They look very similar but if you take a look at block (0,0) you see differences in magnitude and in block (3,5) different orientations.

CPU HOGDescriptor visualization

image description

GPU HOGDescriptor visualization

image description

Could anyone give me some hints why the descriptors are different?

Best regards,

Siegfried