【发布时间】:2017-03-29 16:48:21
【问题描述】:
我正在使用 Python 开发一个使用 OpenCV 的人体检测程序。我看到了this very good example,并在它拥有的样本上运行了它。它可以检测人,无论他们面向哪里,并且具有不错的重叠检测以及模糊运动。
但是,当我在一些我拥有的图像(主要是膝盖向上、腰部向上和胸部向上的照片)上运行它时,我发现该软件并不能完全检测到人。
您可以获取photos from this link。这是我正在使用的代码:
# import the necessary packages
from __future__ import print_function
from imutils.object_detection import non_max_suppression
from imutils import paths
import numpy as np
import argparse
import imutils
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", required=True, help="path to images directory")
args = vars(ap.parse_args())
# initialize the HOG descriptor/person detector
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
# loop over the image paths
imagePaths = list(paths.list_images(args["images"]))
for imagePath in imagePaths:
# load the image and resize it to (1) reduce detection time
# and (2) improve detection accuracy
image = cv2.imread(imagePath)
image = imutils.resize(image, width=min(400, image.shape[1]))
orig = image.copy()
# detect people in the image
(rects, weights) = hog.detectMultiScale(image, winStride=(4, 4),
padding=(8, 8), scale=1.05)
# draw the original bounding boxes
for (x, y, w, h) in rects:
cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 0, 255), 2)
# apply non-maxima suppression to the bounding boxes using a
# fairly large overlap threshold to try to maintain overlapping
# boxes that are still people
rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)
# draw the final bounding boxes
for (xA, yA, xB, yB) in pick:
cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)
# show some information on the number of bounding boxes
filename = imagePath[imagePath.rfind("/") + 1:]
print("[INFO] {}: {} original boxes, {} after suppression".format(
filename, len(rects), len(pick)))
# show the output images
cv2.imshow("Before NMS", orig)
cv2.imshow("After NMS", image)
cv2.waitKey(0)
这很简单。它遍历图像,找到其中的人,然后绘制边界矩形。如果矩形重叠,则将它们连接在一起以防止误报并在一个人中检测到超过 1 个人。
但是,正如我上面提到的,如果人的脚不存在,代码将无法识别人。
有没有办法让 OpenCV 识别视频中可能只有部分身体(膝盖向上、腰部向上、胸部向上)出现的人?在我的用例场景中,我认为寻找手臂和腿并不重要,只要存在躯干和头部,我应该能够看到它。
【问题讨论】:
-
你可以使用 Haar 级联,它已经被训练用于上身检测。请参阅here 及其链接
-
@Miki 似乎训练了上身检测的 Haar Cascades 只能在看到整个身体的情况下才能检测到上身?我可能正在寻找不同的 haar 级联 xml 文件。
-
这对我来说没有多大意义......但我从未使用过它们,所以我无法确定
-
我看到了这个链接answers.opencv.org/question/95834/… 这让我怀疑它,但我认为还有另一个可用的 haar 级联 xml 文件。如果我得到一个好的结果,我会去尝试并更新这个线程。
标签: python opencv opencv3.0 opencv3.1