当前位置:   article > 正文

Python Opencv-contrib Camshift kalman卡尔曼滤波 KCF算法 CSRT算法 目标跟踪实现_卡尔曼滤波目标跟踪 论文代码 python

卡尔曼滤波目标跟踪 论文代码 python

本文为原创文章,转载请注明出处。

本次课题实现目标跟踪一共用到了三个算法,分别是Camshift、Kalman、CSRT,基于Python语言的Tkinter模块实现GUI与接口设计,项目一共包含三个文件:

main.py:

# coding:utf-8
# 主模块


import Tkinter
import tkFileDialog
import cv2
import time
from PIL import ImageTk
# 导入自定义模块
import track
import utils


# 设置窗口800*480
root = Tkinter.Tk()
root.title("基于视频的实时行人追踪")
root.geometry("800x480")

# 设置背景
canvas = Tkinter.Canvas(root, width=800, height=480, highlightthickness=0, borderwidth=0)
background_image = ImageTk.PhotoImage(file="background.jpg")  # 项目本地路径(背景图片)
canvas.create_image(0, 0, anchor="nw", image=background_image)
canvas.pack()

# 显示提示
label_a = Tkinter.Label(root, text="基于视频的实时行人追踪", font=("KaiTi", 20), height=2)
label_a.pack()
canvas.create_window(400, 100, height=25, window=label_a)

# 显示路径
show_path = Tkinter.StringVar()
show_path.set("请选择一个文件夹")

# 显示路径标签
label_b = Tkinter.Label(root, textvariable=show_path, font=("Times New Roman", 15), height=2)
label_b.pack()
canvas.create_window(400, 150, window=label_b)

# 坐标库
ROI = utils.ROI()
# 路径库
path = utils.Path()


# 选择序列
def hit_button_a():
    path.init(tkFileDialog.askdirectory(title="Select Folder"))
    # 显示路径
    if path.img_path != "":
        show_path.set("文件路径:" + str(path.img_path)[:-1] + "\n序列总数:" + str(path.sum))
    else:
        show_path.set("路径错误!")


button_a = Tkinter.Button(root, text="选择序列", font=("KaiTi", 15), height=2, command=hit_button_a)
button_a.pack()
canvas.create_window(400, 200, height=20, window=button_a)


# ROI
def hit_button_b():
    # 读取首帧图像
    first_image = cv2.imread(path.pics_list[0])
    # ROI
    ROI.init_window(cv2.selectROI(windowName="ROI", img=first_image, showCrosshair=True, fromCenter=False))
    cv2.destroyAllWindows()


button_b = Tkinter.Button(root, text="标记目标", font=("KaiTi", 15), heigh=2, command=hit_button_b)
button_b.pack()
canvas.create_window(400, 250, height=20, window=button_b)


# 目标追踪

def hit_button_c():
    global camshift, kcf, csrt
    index = utils.index(path.groundtruth_path)  # 读取真值
    firstframe = True
    kalman_xy = track.KalmanFilter()
    kalman_size = track.KalmanFilter()
    bbox = [0, 0, 0, 0]

    for i in range(0, path.sum):
        start = time.time()  # 开始计时
        frame = cv2.imread(path.pics_list[i])  # 读取
        if firstframe:
            camshift = track.Camshift(frame, ROI.window)
            kcf = track.KCFtracker(frame, ROI.window)
            firstframe = False
            continue
        # camshift.update(frame)
        ok = kcf.update(frame)
        if not ok:
            mes = (bbox[0], bbox[1], bbox
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/864741
推荐阅读
相关标签
  

闽ICP备14008679号