uoip / kcfpy Goto Github PK
View Code? Open in Web Editor NEWPython implementation of KCF tracking algorithm
License: MIT License
Python implementation of KCF tracking algorithm
License: MIT License
I ran the code, it can track single-target, how to improve the code to achieve multi-target tracking
def getFeatures(self, image, inithann, scale_adjust=1.0):
extracted_roi = [0,0,0,0] #[int,int,int,int]
cx = self._roi[0] + self._roi[2]/2 #float
cy = self._roi[1] + self._roi[3]/2 #float
if(inithann):
padded_w = self._roi[2] * self.padding
padded_h = self._roi[3] * self.padding
if(self.template_size > 1):
if(padded_w >= padded_h):
self._scale = padded_w / float(self.template_size)
else:
self._scale = padded_h / float(self.template_size)
self._tmpl_sz[0] = int(padded_w / self._scale)
self._tmpl_sz[1] = int(padded_h / self._scale)
else:
self._tmpl_sz[0] = int(padded_w)
self._tmpl_sz[1] = int(padded_h)
self._scale = 1.
if(self._hogfeatures):
self._tmpl_sz[0] = int(self._tmpl_sz[0]) / (2*self.cell_size) * 2*self.cell_size + 2*self.cell_size
self._tmpl_sz[1] = int(self._tmpl_sz[1]) / (2*self.cell_size) * 2*self.cell_size + 2*self.cell_size
else:
self._tmpl_sz[0] = int(self._tmpl_sz[0]) / 2 * 2
self._tmpl_sz[1] = int(self._tmpl_sz[1]) / 2 * 2
extracted_roi[2] = int(scale_adjust * self._scale * self._tmpl_sz[0])
extracted_roi[3] = int(scale_adjust * self._scale * self._tmpl_sz[1])
extracted_roi[0] = int(cx - extracted_roi[2]/2)
extracted_roi[1] = int(cy - extracted_roi[3]/2)
z = subwindow(image, extracted_roi, cv2.BORDER_REPLICATE)
if(z.shape[1]!=self._tmpl_sz[0] or z.shape[0]!=self._tmpl_sz[1]):
z = cv2.resize(z, tuple(self._tmpl_sz))
if(self._hogfeatures):
mapp = {'sizeX':0, 'sizeY':0, 'numFeatures':0, 'map':0}
mapp = fhog.getFeatureMaps(z, self.cell_size, mapp)
mapp = fhog.normalizeAndTruncate(mapp, 0.2)
mapp = fhog.PCAFeatureMaps(mapp)
self.size_patch = map(int, [mapp['sizeY'], mapp['sizeX'], mapp['numFeatures']])
FeaturesMap = mapp['map'].reshape((self.size_patch[0]*self.size_patch[1], self.size_patch[2])).T # (size_patch[2], size_patch[0]*size_patch[1])
else:
if(z.ndim==3 and z.shape[2]==3):
FeaturesMap = cv2.cvtColor(z, cv2.COLOR_BGR2GRAY) # z:(size_patch[0], size_patch[1], 3) FeaturesMap:(size_patch[0], size_patch[1]) #np.int8 #0~255
elif(z.ndim==2):
FeaturesMap = z #(size_patch[0], size_patch[1]) #np.int8 #0~255
FeaturesMap = FeaturesMap.astype(np.float32) / 255.0 - 0.5
self.size_patch = [z.shape[0], z.shape[1], 1]
if(inithann):
self.createHanningMats() # createHanningMats need size_patch
FeaturesMap = self.hann * FeaturesMap
return FeaturesMap
Thanks for sharing with us. If somebody wants to use python3 version, you can take reference on https://github.com/LCorleone/KCF_py3
I found when the target is lost,it is hard to retrack the lost target,how to solve this problem?
Zoomed-in bounding boxes are never getting smaller.
is there any one have this problem when run the code in python3 environment ?
can you give me help to solve this problem.
Dear uoip:
First of all, thanks for your work very much. You write a python wrapper for KCFcpp. I want to make use of it. But I have a question that what kind of change will python setup.py build_ext --inplace
will have on my systerm? How can I withdraw the changes?
I am new to github. I cannot find the issues column in the uoip/KCFcpp-py-wrapper, so I asked here. Looking forward to get your response ^_^
I konw the opencv API have the flag .
such as --> retval, boundingBox = cv.Tracker.update( image )
the flag is retval to find the object wehter lost .
-->Problem ONE :
but the API has a big disadvantages that it cant re-init the Tracker(in other word ,we cant init a tracker 2 times ).
And I need the function (re-init ),so i must use the kcf (joaofaro/KCFcpp),this code has the function ,we can init the Tracker many times.
-->Problem TWO :
so can you give me some advice for how to use the peak_value (just like use the flag in opencv API )?
-->Problem THREE :
uoip/KCFcpp-py-wrapper
I use the python kcf wrappered from c++ kcf ( joao .f).
do you have any good ideas about how can I find the target wether lost?
Thanks a lot for great code, I still have some questions
Does it use SVM?
What is the “peak value” returned and what is its range?
where actually it look in the new frame for the object?
in kcftracker.py:
209-213 should be to make sure self._tmpl_sz can be divisible by self.cell_size:
if(self._hogfeatures):
self._tmpl_sz[0] = int(self._tmpl_sz[0] / (2self.cell_size)) * 2self.cell_size + 2self.cell_size
self._tmpl_sz[1] = int(self._tmpl_sz[1] / (2self.cell_size)) * 2self.cell_size + 2self.cell_size
else:
self._tmpl_sz[0] = int(self._tmpl_sz[0] / 2) * 2
self._tmpl_sz[1] = int(self._tmpl_sz[1] / 2) * 2
Traceback (most recent call last):
File "run.py", line 75, in
tracker.init([ix,iy,w,h], frame)
File "/home/hp/zjc/nk_PyCharm/PyCharm_project/nk_KCF/3_uoip-KCFpy
/KCFpy/kcftracker.py", line 269, in init
self._tmpl = self.getFeatures(image, 1)
File "/home/hp/zjc/nk_PyCharm/PyCharm_project/nk_KCF/3_uoip-KCFpy
/KCFpy/kcftracker.py", line 185, in getFeatures
cx = self._roi[0] + self._roi[2]/2 #float
TypeError: 'map' object is not subscriptable
Hi, thank you for sharing this awesome python implementation.
Can you please implement the DCF function in python?
In the paper, the author clams that DCF is 70% faster than KCF, with only little accuracy lose.
The original matlab code does implement both KCF & DCF
http://www.robots.ox.ac.uk/~joao/circulant/
It seems that there is only slightly changes between 2 correlation functions.
I have run your code, but I found the performance has some gap between these cpp and py version.
1. the cpp version has a better scale invariance
2. the py version is easily tend to lose target
and I still run some other version of cpp code such as vojirt/kcf and foolwood/KCF, they remain the same problems.
Do you have worked out this weird problem?
Hello, I met a problem when running the code as follows:TypeError: _jit_decorator() takes exactly 1 argument (7 given). But I have checked the fhog.py and find the func1 does provide 7 arguments. Does anybody have some idea and help me?
Traceback (most recent call last):
File "/Users/guomuqi/Downloads/KCFpy-master/run.py", line 75, in
tracker.init([ix,iy,w,h], frame)
File "/Users/guomuqi/Downloads/KCFpy-master/kcftracker.py", line 274, in init
self.train(self.tmpl, 1.0)
File "/Users/guomuqi/Downloads/KCFpy-master/kcftracker.py", line 261, in train
k = self.gaussianCorrelation(x, x)
File "/Users/guomuqi/Downloads/KCFpy-master/kcftracker.py", line 171, in gaussianCorrelation
c = rearrange(c)
File "/Users/guomuqi/Downloads/KCFpy-master/kcftracker.py", line 38, in rearrange
img[0:yh,0:xh], img_[yh:img.shape[0],xh:img.shape[1]] = img[yh:img.shape[0],xh:img.shape[1]], img[0:yh,0:xh]
TypeError: slice indices must be integers or None or have an index method
Did anyone else run into this problem?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.