def compute(self, frame):
#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
dx = cv2.filter2D(frame, cv2.CV_32F, self.xkernel)
dy = cv2.filter2D(frame, cv2.CV_32F, self.ykernel)
orientations = np.zeros_like(dx)
magnitudes = np.zeros_like(dx)
cv2.cartToPolar(dx,dy, magnitudes,orientations)
descriptor = []
frameH, frameW = frame.shape
mask_threshold = magnitudes <= self.threshold
for row in range(self.rows):
for col in range(self.cols):
mask = np.zeros_like(frame)
mask[((frameH/self.rows)*row):((frameH/self.rows)*(row+1)),(frameW/self.cols)*col:((frameW/self.cols)*(col+1))] = 1
mask[mask_threshold] = 0
a_, b_ = mask.shape
hist = cv2.calcHist([orientations], self.channel, mask, [self.bins], self.range)
hist = cv2.normalize(hist, None)
descriptor.append(hist)
return np.concatenate([x for x in descriptor])
评论列表
文章目录