Example #1
0
 def __build_descriptors(self):
     for k in range(0, len(self.__features)):
         (x, y, s, _) = self.__features[k]
         sigma = SIGMA[s]
         l = int(0.5*sigma)
         theta = self.__orientation[k]
         cosT, sinT = np.cos(theta), np.sin(theta)
         descriptor = np.zeros((64))
         k = 0
         for (i, j) in itertools.product(range(0, 4), range(0, 4)):
             sum_resp_x = sum_resp_y = sum_abs_resp_x = sum_abs_resp_y = 0
             for (m, n) in itertools.product(range(0, 5), range(0, 5)):
                 X = cv.Round(x + sigma*(cosT*(5*(i-2) + m) - sinT*(5*(j-2) + n)))
                 Y = cv.Round(y + sigma*(sinT*(5*(i-2) + m) + cosT*(5*(j-2) + n)))
                 gauss = mt.gaussian(X-x, Y-y, 3.3*sigma)
                 resp_x = self.__integralImage.haarX(X, Y, l)
                 resp_y = self.__integralImage.haarY(X, Y, l)
                 respX = gauss*(-sinT*resp_x + cosT*resp_y)
                 respY = gauss*(cosT*resp_x + sinT*resp_y)
                 sum_resp_x += respX
                 sum_resp_y += respY
                 sum_abs_resp_x += np.abs(respX)
                 sum_abs_resp_y += np.abs(respY)
             descriptor[k] = sum_resp_x
             descriptor[k+1] = sum_resp_y
             descriptor[k+2] = sum_abs_resp_x
             descriptor[k+3] = sum_abs_resp_y
             k = k + 4
         norm = np.linalg.norm(descriptor)
         self.__descriptors.append(descriptor / norm)   
Example #2
0
 def __find_orientation(self):
     for (x, y, s, _) in self.__features:
         sigma = SIGMA[s]
         l = int(sigma)
         haar_respX = {}
         haar_respY = {}
         angle = {}
         indexes = set(itertools.product(range(-6, 7), range(-6, 7)))
         for (i, j) in [elem for elem in indexes if (elem[0]**2 + elem[1]**2) <= 36]:
             X, Y = cv.Round(x + i * sigma), cv.Round(y + j * sigma)
             gauss = mt.gaussian(X-x, Y-y, 2*sigma)
             haar_respX[(i, j)] = self.__integralImage.haarX(X, Y, l) * gauss
             haar_respY[(i, j)] = self.__integralImage.haarY(X, Y, l) * gauss
             angle[(i, j)] = cv.FastArctan(haar_respY[(i, j)], haar_respX[(i, j)])
         max_length = 0
         max_resp_x = max_resp_y = 0
         for theta in range(Surf.STARTING_ANGLE, Surf.LAST_ANGLE):
             resp_x = resp_y = 0
             for p in [index for index in angle.keys() if (theta - 30 <= angle[index] and 
                                                           angle[index] <= theta + 30)]:
                 resp_x += haar_respX[p]
                 resp_y += haar_respY[p]
             resp_len = resp_x**2 + resp_y**2
             if resp_len > max_length:
                 max_resp_x, max_resp_y = resp_x, resp_y
                 max_length = resp_len
         self.__orientation.append(cv.FastArctan(max_resp_y, max_resp_x) * mt.TO_RADS_RATIO)