• 大小: 9KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: Python
  • 标签: KCF  python  

资源简介

KCF全称为Kernel Correlation Filter 核相关滤波算法。是在2014年由Joao F. Henriques, Rui Caseiro, Pedro Martins, and Jorge Batista提出来的。本程序是KCF算法的python实现

资源截图

代码片段和文件信息

import numpy as np 
import cv2
from numba import jit

# constant
NUM_SECTOR = 9
FLT_EPSILON = 1e-07


@jit
def func1(dx dy boundary_x boundary_y height width numChannels):
    r = np.zeros((height width) np.float32)
    alfa = np.zeros((height width 2) np.int)

    for j in xrange(1 height-1):
        for i in xrange(1 width-1):
            c = 0
            x = dx[j i c]
            y = dy[j i c]
            r[j i] = np.sqrt(x*x + y*y)

            for ch in xrange(1 numChannels):
                tx = dx[j i ch]
                ty = dy[j i ch]
                magnitude = np.sqrt(tx*tx + ty*ty)
                if(magnitude > r[j i]):
                    r[j i] = magnitude
                    c = ch
                    x = tx
                    y = ty

            mmax = boundary_x[0]*x + boundary_y[0]*y
            maxi = 0

            for kk in xrange(0 NUM_SECTOR):
                dotProd = boundary_x[kk]*x + boundary_y[kk]*y
                if(dotProd > mmax):
                    mmax = dotProd
                    maxi = kk
                elif(-dotProd > mmax):
                    mmax = -dotProd
                    maxi = kk + NUM_SECTOR

            alfa[j i 0] = maxi % NUM_SECTOR
            alfa[j i 1] = maxi
    return r alfa

@jit
def func2(dx dy boundary_x boundary_y r alfa nearest w k height width sizeX sizeY p stringSize):
    mapp = np.zeros((sizeX*sizeY*p) np.float32)
    for i in xrange(sizeY):
        for j in xrange(sizeX):
            for ii in xrange(k):
                for jj in xrange(k):
                    if((i * k + ii > 0) and (i * k + ii < height - 1) and (j * k + jj > 0) and (j * k + jj < width  - 1)):
                        mapp[i*stringSize + j*p + alfa[k*i+iij*k+jj0]] +=  r[k*i+iij*k+jj] * w[ii0] * w[jj0]
                        mapp[i*stringSize + j*p + alfa[k*i+iij*k+jj1] + NUM_SECTOR] +=  r[k*i+iij*k+jj] * w[ii0] * w[jj0]
                        if((i + nearest[ii] >= 0) and (i + nearest[ii] <= sizeY - 1)):
                            mapp[(i+nearest[ii])*stringSize + j*p + alfa[k*i+iij*k+jj0]] += r[k*i+iij*k+jj] * w[ii1] * w[jj0]
                            mapp[(i+nearest[ii])*stringSize + j*p + alfa[k*i+iij*k+jj1] + NUM_SECTOR] += r[k*i+iij*k+jj] * w[ii1] * w[jj0]
                        if((j + nearest[jj] >= 0) and (j + nearest[jj] <= sizeX - 1)):
                            mapp[i*stringSize + (j+nearest[jj])*p + alfa[k*i+iij*k+jj0]] += r[k*i+iij*k+jj] * w[ii0] * w[jj1]
                            mapp[i*stringSize + (j+nearest[jj])*p + alfa[k*i+iij*k+jj1] + NUM_SECTOR] += r[k*i+iij*k+jj] * w[ii0] * w[jj1]
                        if((i + nearest[ii] >= 0) and (i + nearest[ii] <= sizeY - 1) and (j + nearest[jj] >= 0) and (j + nearest[jj] <= sizeX - 1)):
                            mapp[(i+nearest[ii])*stringSize + (j+nearest[jj])*p + alfa[k*i+iij*k+jj0]] += r[k*i+iij*k+jj] * w[ii1] * w[jj1]
                            mapp[(

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-01-06 15:52  KCFpy-master\
     文件        1061  2017-01-06 15:52  KCFpy-master\LICENSE
     文件        1807  2017-01-06 15:52  KCFpy-master\README.md
     文件       12483  2017-01-06 15:52  KCFpy-master\fhog.py
     文件       11668  2017-01-06 15:52  KCFpy-master\kcftracker.py
     文件        2420  2017-01-06 15:52  KCFpy-master\run.py

评论

共有 条评论