因此,我正在尝试计划我想采取的方法来计算视频中的车辆和行人。以下是我想采取的方法的基本步骤。
问题:这种方法是否适用于行人和车辆?如果是这样,我不清楚如何区分不同的blob?
我想知道blob的大小是否可以用来区分行人(小斑点)和车辆(大斑点)。但是,我不知道如何处理车辆距离货源更远的情况,因此看起来很小。
import numpy as np
import cv2
cap = cv2.VideoCapture('video.avi')
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))
fgbg = cv2.BackgroundSubtractorMOG(500, 6, 0.9, 1)
# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 10;
params.maxThreshold = 200;
# Filter by Area.
params.filterByArea = True
params.minArea = 400
# Filter by Circularity
params.filterByCircularity = True
params.minCircularity = 0.1
# Filter by Convexity
params.filterByConvexity = True
params.minConvexity = 0.87
# Filter by Inertia
params.filterByInertia = True
params.minInertiaRatio = 0.01
# Create a detector with the parameters
ver = (cv2.__version__).split('.')
if int(ver[0]) < 3 :
detector = cv2.SimpleBlobDetector(params)
else :
detector = cv2.SimpleBlobDetector_create(params)
while(1):
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
fgmask = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel)
#fgmask = frame;
# Detect blobs.
keypoints = detector.detect(fgmask)
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(frame, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
print keypoints
cv2.imshow('frame',im_with_keypoints)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
答案 0 :(得分:0)
我建议不要采用斑点区域方法来区分行人和车辆。你已经解释了一个明显的缺点 - 更远的汽车肯定会被当作行人。
在步骤2和3之间需要涉及更复杂的逻辑,例如:
在最终解决方案中至少有一个子弹是我必须拥有一个良好的准确性解决方案。拥有它们两者甚至可以更好地准确。