python - 如何绘制被跟踪人员的轨迹
问题描述
我正在尝试使用卡尔曼滤波器在 opencv 中绘制被跟踪人员的轨迹。
我正在尝试以下代码,但两个结尾行是无限的
def pipeline(img, tracker, det):
global cnt
z_box = det.get_localization(img)
detections = tracker.update(np.array(z_box))
prev= []
cnt = cnt + 1
for trk in detections:
trk = trk.astype(np.int32)
img = helpers.draw_box_label(img, trk, trk[4]) # Draw the bounding boxes on the
if cnt < 20:
prev.append(trk)
else:
cnt = 0
prev = []
for i in range(0,len(prev)-1):
left1, top1, right1, bottom1 = prev[i][1], prev[i][0], prev[i][3], prev[i][2]
left2, top2, right2, bottom2 = prev[i+1][1], prev[i+1][0], prev[i+1][3], prev[i+1][2]
cv2.line(img, pt1=((int(left1 + right1 / 2)), int(top1 + bottom1 / 2)),pt2=(int((left2 + right2) / 2), int((top2 + bottom2) / 2)), color=(255,0,255))
return img
我想绘制轨迹如下图
根据评论,我尝试了这个,但仍然没有工作。
for trk in detections:
trk = trk.astype(np.int32)
img = helpers.draw_box_label(img, trk, trk[4]) # Draw the bounding boxes on the
if cnt < 20:
left2, top2, right2, bottom2 = trk[1], trk[0], trk[3], trk[2]
prev.append( np.array([int(left2 + right2)/2, int(right2+bottom2)/2]))
else:
cnt = 0
prev = []
cv2.polylines(img,np.int32([prev]), True, color=(255,0,0))
解决方案
推荐阅读
- aws-codebuild - CodeBuild Windows 容器内容
- google-apps-script - 使用谷歌翻译翻译整个谷歌表格
- javascript - 为什么在array.filter,lambda中得到这个结果?javascript
- javascript - 如何用 SVG 弧线为指南针的 8 个方向绘制 1/4 弧线?
- php - 查询数据库的行,如果返回结果,检查列是否 = $_SESSION 值,然后做点什么?
- reactjs - 使用角色、testid 和类名反应渲染测试
- python - Jupyter notebook 无法从 nb_conda_kernels 找到 conda 环境的内核
- javascript - 如何使用 javascript 中的谷歌图表将 x 轴点交换为 y 轴
- c - 在 C 中创建新结构时如何正确分配足够的内存(malloc)?
- android-studio - 我可以在Android Studio的不同功能中两次初始化相同的图像吗