Forums - HOG SVM Implementation Problems

2 posts / 0 new
Last post
HOG SVM Implementation Problems
adrian.iordache
Join Date: 24 Apr 19
Posts: 1
Posted: Wed, 2019-04-24 07:08
Hello, I am trying to implement a SVM with Histogram of Oriented Gradients (HOG) using FastCV APIs and I have a few questions:
 
I use for testing purposes a 16x16 grayscale image loaded with OpenCV and coverted in a uint8_t pointer.
I successfully extracted xbuffer and ybuffer using fcvImageGradientSobelPlanars16
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
int16_t* xbuffer = (int16_t*)malloc(size * sizeof(int16_t));
memset(xbuffer, 0, (size * sizeof(int16_t)));
int16_t* ybuffer = (int16_t*)malloc(size * sizeof(int16_t));
memset(ybuffer, 0, (size * sizeof(int16_t)));
 
//Calculate the gradient vector in the X and Y direction
fcvImageGradientSobelPlanars16(pixels, width, height, 0, xbuffer, ybuffer);
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
After that I used those buffers to obtain strength gradient vector and orientation gradient vector:
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//Strength gradient vector
int16_t* strength = (int16_t*)malloc(size * sizeof(int16_t));
memset(strength, 0, (size * sizeof(int16_t)));
int magnitudeCod = fcvMagnitudes16(xbuffer, width, height, 0, ybuffer, 0, strength, 0);
 
 
//Orientation gradient vector
uint8_t* orientation = (uint8_t*)malloc(size * sizeof(uint8_t));
memset(orientation, 0, (size * sizeof(int16_t)));
int angleCod = fcvPhases16(xbuffer, width, height, 0, ybuffer, 0, orientation, 0);
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
I noticed that my orientation vector has values between 0 and 255 (from documentation) so I will use FASTCV_HOG_NORM_FHOG
 
After that I convert those to uint16_t* so I can use them with fcvExtractHOGu16
 
The parameters for HOG:
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//HOG Parameters
uint32_t widthHOG = 16;
uint32_t heightHOG = 16;
uint32_t strengthStride = 0;
uint32_t orientationStride = 0;
uint32_t cellSize = 4;
uint32_t blockSize = 4;
uint32_t blockStep = 4;
uint32_t binSize = 9;
fcvHOGNormMethod normMethod = FASTCV_HOG_NORM_FHOG;
uint32_t flen = 0;
 
void* handle;
 
uint32_t vec_length = 0;
int codInit = fcvHOGInit(widthHOG, heightHOG, cellSize, blockSize, blockStep, binSize, normMethod, &vec_length, &handle);
Iout << "Length of vector: "<<vec_length<<endl; 
 
//Length of vector: 128
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
 
First Question: Why the length of the vector is 128, I expected to be 144 because there are 9 bins and the blockSize is equal to cellSize so the image will be splitted in 16 cells
with dimensions 4 x 4, and for each cell should be 9 bins, so that's why I expected to be 144 = 9 * 16.
And the biggest problem is that 128 is not divisible by 9 (number of bins), and that's why I need to ask, are those bins?
 
Second Question: What are the parameters flen and handle? They do not appear in the documentation
 
Observation: fcvGetHOGVectorLengthu32 method does not exist
 
After that I tried to obtain the descriptor vector from strength and orientation using fcvExtractHOGu16
 
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
uint16_t* hogVector = (uint16_t*)malloc(vec_length * sizeof(uint16_t));
memset(hogVector, 0, (vec_length * sizeof(uint16_t)));
 
int codExtract = fcvExtractHOGu16(strengthTemp, width, height, strengthStride, orientationTemp, orientationStride, cellSize, blockSize, blockStep, binSize, normMethod, hogVector, flen, handle);
Iout <<"Extract Code: "<< codExtract <<endl;
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
 
Third Question: What are the values inside the hogVector and is correct that the size is equal to vec_length?
Fourth Question: We need to normalize the values inside the hogVector somehow?
Fifth Question: Is there need to use that void* handle somehow beside deallocation?
 
 
The next step would be to take that descriptor vector and use it inside fcvSVMPredict2Classf32 as vec parameter and with my support vectors obtained from a libsvm model as sv parameter
 
Sixth Question: How do we use hogVector from fcvExtractHOGu16 in fcvSVMPredict2Classf32 because hogVector is of type uint16_t* and in the fcvSVMPredict2Classf32 we need float32_t*, again we need to normalize?
 
Every function used until now returns FASTCV_SUCCESS, but we don't know clearly what is the output because it is not explained in documentation
 
Thank you in advance for your answers,
Adrian Iordache
  • Up0
  • Down0
f.anusha
Join Date: 20 Nov 20
Posts: 3
Posted: Fri, 2021-01-29 23:53

Hi,

what are thr parameter r u passing in fcvImageGradientSobelPlanars16_v2(), in that what is const uint8_t *__restrict src, what dx and dy containing.

Thank you in advance

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.