问题描述
你好,我需要更改质心跟踪器的逻辑,以便它可以从左向右跟踪人,反之亦然,而不是上下跟踪
我尝试在循环中将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 (将#修改为@)