HOGDescriptor with videos to recognize objects

前端 未结 2 1063
不思量自难忘°
不思量自难忘° 2021-02-06 16:37

Unfortunately I am both a python and a openCV beginner, so wish to excuse me if the question is stupid.

I am trying to use a cv2.HOGDescriptor to recognize

相关标签:
2条回答
  • 2021-02-06 16:59

    There is no need to perform that extra conversion yourself, that problem is related to the mixing of the new and old OpenCV bindings for Python. The other problem regarding hog.detectMultiScale is simply due to incorrect parameter ordering.

    The second problem can be directly seen by checking help(cv2.HOGDescriptor().detectMultiScale):

    detectMultiScale(img[, hitThreshold[, winStride[, padding[, 
               scale[, finalThreshold[, useMeanshiftGrouping]]]]]])
    

    as you can see, every parameter is optional but the first (the image). The ordering is also important, since you are effectively using winStride as the first, while it is expected to be the second, and so on. You can used named arguments to pass it. (All this has been observed in the earlier answer.)

    The other problem is the code mix, here is a sample code that you should consider using:

    import sys
    import cv2
    
    hog = cv2.HOGDescriptor()
    hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
    hogParams = {'winStride': (8, 8), 'padding': (32, 32), 'scale': 1.05}
    
    video = cv2.VideoCapture(sys.argv[1])
    while True:
        ret, frame = video.read()
        if not ret:
            break
    
        result = hog.detectMultiScale(frame, **hogParams)
        print result
    
    0 讨论(0)
  • 2021-02-06 16:59

    The documentation for the C++ version of HOGDescriptor::detectMultiScale shows a hit_threshold parameter (of type double) prior to the win_stride argument. So it appears you are missing an argument to the function. To accept the default argument for win_stride, you should pass your addition arguments used in your question as keywords.

    0 讨论(0)
提交回复
热议问题