OpenCV函数HOGDescriptor detectMultiScale的参数填充是什么意思? 你能告诉我更多关于它的事吗? 我的代码如下:
import cv2
cap = cv2.VideoCapture('E:/xingren.mp4')
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
fps = cap.get(cv2.CAP_PROP_FPS)
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
v = cv2.VideoWriter('E:/20171127.mp4', fourcc, fps, size)
def draw_detections(img, rects, thickness = 1):
for x, y, w, h in rects:
pad_w, pad_h = int(0.15 * w), int(0.05 * h)
cv2.rectangle(img, (x + pad_w, y + pad_h), (x + w - pad_w, y + h - pad_h), (0, 255, 0), thickness)
def PD_default(filename):
image = filename
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
found, w = hog.detectMultiScale(image, hitThreshold = 0, winStride = (8,8), padding = (0, 0), scale = 1.05, finalThreshold = 5)
draw_detections(image, found)
cv2.imshow('original', image)
v.write(image)
while(True):
ret, frame = cap.read()
if ret:
PD_default(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
答案 0 :(得分:0)
如果你查看源文件,你会看到填充被添加到图像的宽度和高度,它不能是负数。对于大多数情况,默认值0
应该足够了。
size_t nwindows = locations.size();
padding.width = (int)alignSize(std::max(padding.width, 0), cacheStride.width);
padding.height = (int)alignSize(std::max(padding.height, 0), cacheStride.height);
Size paddedImgSize(img.cols + padding.width*2, img.rows + padding.height*2);
HOGCache cache(this, img, padding, padding, nwindows == 0, cacheStride);
来源:https://github.com/opencv/opencv/blob/master/modules/objdetect/src/hog.cpp