KCFpy
KCFpy copied to clipboard
I think the code has some question in ' def getFeature()'
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
FeaturesMap i find the FeaturesMap is a local variables .and not be define before