如何解决如何在质心跟踪器中水平跟踪
你好,我需要更改质心跟踪器的逻辑,以便它可以从左向右跟踪人,反之亦然,而不是上下跟踪
我尝试在循环中将y更改为x,并且它不起作用,请使用质心跟踪器将(1)旧对象,质心与(2)新计算的对象质心相关联
cv2.line(frame,(0,H // 2),(W,255,255),2)
objects = ct.update(rects)
# loop over the tracked objects
for (objectID,centroid) in objects.items():
# check to see if a trackable object exists for the current
# object ID
to = trackableObjects.get(objectID,None)
# if there is no existing trackable object,create one
if to is None:
to = TrackableObject(objectID,centroid)
# otherwise,there is a trackable object so we can utilize it
# to determine direction
else:
# the difference between the y-coordinate of the *current*
# centroid and the mean of *previous* centroids will tell
# us in which direction the object is moving (negative for
# 'up' and positive for 'down')
y = [c[1] for c in to.centroids]
direction = centroid[1] - np.mean(y)
to.centroids.append(centroid)
# check to see if the object has been counted or not
if not to.counted:
# if the direction is negative (indicating the object
# is moving up) AND the centroid is above the center
# line,count the object
if direction < 0 and centroid[1] < H // 2:
totalUp += 1
to.counted = True
# if the direction is positive (indicating the object
# is moving down) AND the centroid is below the
# center line,count the object
elif direction > 0 and centroid[1] > H // 2:
totalDown += 1
to.counted = True
# store the trackable object in our dictionary
trackableObjects[objectID] = to
# draw both the ID of the object and the centroid of the
# object on the output frame
text = "ID {}".format(objectID)
cv2.putText(frame,text,(centroid[0] - 10,centroid[1] - 10),cv2.FONT_HERSHEY_SIMPLEX,0.5,0),2)
cv2.circle(frame,(centroid[0],centroid[1]),4,-1)
# construct a tuple of information we will be displaying on the
# frame
info = [
("Up",totalUp),("Down",totalDown),("Status",status),]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。