OpenCV HOGDescripter Python

后端 未结 2 693
余生分开走
余生分开走 2020-12-08 05:43

I was wondering if anyone knew why there is no documentation for HOGDescriptors in the Python bindings of OpenCV.

Maybe I\'ve just missed them, but the only code I\'

2条回答
  •  执笔经年
    2020-12-08 06:29

    1. Get Inbuilt Documentation: Following command on your python console will help you know the structure of class HOGDescriptor:

    import cv2 help(cv2.HOGDescriptor())

    2. Example code: Here is a snippet of code to initialize an cv2.HOGDescriptor with different parameters (The terms I used here are standard terms which are well defined in OpenCV documentation here):

    import cv2
    image = cv2.imread("test.jpg",0)
    winSize = (64,64)
    blockSize = (16,16)
    blockStride = (8,8)
    cellSize = (8,8)
    nbins = 9
    derivAperture = 1
    winSigma = 4.
    histogramNormType = 0
    L2HysThreshold = 2.0000000000000001e-01
    gammaCorrection = 0
    nlevels = 64
    hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,
                            histogramNormType,L2HysThreshold,gammaCorrection,nlevels)
    #compute(img[, winStride[, padding[, locations]]]) -> descriptors
    winStride = (8,8)
    padding = (8,8)
    locations = ((10,20),)
    hist = hog.compute(image,winStride,padding,locations)
    

    3. Reasoning: The resultant hog descriptor will have dimension as: 9 orientations X (4 corner blocks that get 1 normalization + 6x4 blocks on the edges that get 2 normalizations + 6x6 blocks that get 4 normalizations) = 1764. as I have given only one location for hog.compute().

    4. Different way to initialize HOGDescriptor:
    One more way to initialize is from xml file which contains all parameter values:

    hog = cv2.HOGDescriptor("hog.xml")
    

    To get an xml file one can do following:

    hog = cv2.HOGDescriptor()
    hog.save("hog.xml")
    

    and edit the respective parameter values in xml file.

提交回复
热议问题