Extracting HoG Features using OpenCV

前端 未结 4 548
醉话见心
醉话见心 2020-12-12 11:09

I am trying to extract features using OpenCV\'s HoG API, however I can\'t seem to find the API that allow me to do that.

What I am trying to do is to extract feature

4条回答
  •  感动是毒
    2020-12-12 11:48

    You can use hog class in opencv as follows

    HOGDescriptor hog;
    vector ders;
    vector locs;
    

    This function computes the hog features for you

    hog.compute(grayImg, ders, Size(32, 32), Size(0, 0), locs);
    

    The HOG features computed for grayImg are stored in ders vector to make it into a matrix, which can be used later for training.

    Mat Hogfeat(ders.size(), 1, CV_32FC1);
    
    for(int i=0;i(i,0)=ders.at(i);
    

    Now your HOG features are stored in Hogfeat matrix.

    You can also set the window size, cell size and block size by using object hog as follows:

    hog.blockSize = 16;
    hog.cellSize = 4;
    hog.blockStride = 8;
    
    // This is for comparing the HOG features of two images without using any SVM 
    // (It is not an efficient way but useful when you want to compare only few or two images)
    // Simple distance
    // Consider you have two HOG feature vectors for two images Hogfeat1 and Hogfeat2 and those are same size.
    
    double distance = 0;
    for(int i = 0; i < Hogfeat.rows; i++)
        distance += abs(Hogfeat.at(i, 0) - Hogfeat.at(i, 0));
    
    if (distance < Threshold)
        cout<<"Two images are of same class"<

    Hope it is useful :)

提交回复
热议问题