代码拉取完成,页面将自动刷新
import cv2
OPENCV_MAJOR_VERSION = int(cv2.__version__.split('.')[0])
OPENCV_MINOR_VERSION = int(cv2.__version__.split('.')[1])
def is_inside(i, o):
ix, iy, iw, ih = i
ox, oy, ow, oh = o
return ix > ox and ix + iw < ox + ow and \
iy > oy and iy + ih < oy + oh
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
img = cv2.imread('../images/haying.jpg')
if OPENCV_MAJOR_VERSION >= 5 or \
(OPENCV_MAJOR_VERSION == 4 and OPENCV_MINOR_VERSION >= 6):
# OpenCV 4.6 or a later version is being used.
found_rects, found_weights = hog.detectMultiScale(
img, winStride=(4, 4), scale=1.02, groupThreshold=1.9)
else:
# OpenCV 4.5 or an earlier version is being used.
# The groupThreshold parameter used to be named finalThreshold.
found_rects, found_weights = hog.detectMultiScale(
img, winStride=(4, 4), scale=1.02, finalThreshold=1.9)
found_rects_filtered = []
found_weights_filtered = []
for ri, r in enumerate(found_rects):
for qi, q in enumerate(found_rects):
if ri != qi and is_inside(r, q):
break
else:
found_rects_filtered.append(r)
found_weights_filtered.append(found_weights[ri])
for ri, r in enumerate(found_rects_filtered):
x, y, w, h = r
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 255), 2)
text = '%.2f' % found_weights_filtered[ri]
cv2.putText(img, text, (x, y - 20),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2)
cv2.imshow('Women in Hayfield Detected', img)
cv2.imwrite('./women_in_hayfield_detected.png', img)
cv2.waitKey(0)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。