Esempio n. 1
0
 def dof(j0, j1, jc=None):
     x0, y0 = ps[j0]
     x1, y1 = ps[j1]
     f = 1
     if jc is not None:
         xc, yc = ps[jc]
         a = math.clamp(
             math.dot(math.norm((xc - x0, yc - y0)),
                      math.norm((x1 - xc, y1 - yc))), -0.999, 0.999)
         f = 1 / math.cos(math.acos(a) / 2)
     return math.norm((x1 - x0, y1 - y0), w * f)
Esempio n. 2
0
 def constrain(self, pos, j):
     if pos[1] < 0.0001:
         pos = pos[0], 0.0001
     if pos[0] < self.width:
         pos = self.width, pos[1]
     if math.dot(math.norm(pos), (C30, -S30)) > -self.width:
         pos, _ = ptoline(pos, (S30, C30))
         pos = pos[0] - self.width * C30, pos[1] + self.width * S30
     a = math.length(pos)
     if a > 1 - self.width:
         pos = math.norm(pos, 1 - self.width)
     return pos
Esempio n. 3
0
def hog(img):
    gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
    gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
    mag, ang = cv2.cartToPolar(gx, gy)
    bin_n = 16 # Number of bins
    bin = np.int32(bin_n*ang/(2*np.pi))

    bin_cells = []
    mag_cells = []

    cellx = celly = 8

    for i in range(0,img.shape[0]/celly):
        for j in range(0,img.shape[1]/cellx):
            bin_cells.append(bin[i*celly : i*celly+celly, j*cellx : j*cellx+cellx])
            mag_cells.append(mag[i*celly : i*celly+celly, j*cellx : j*cellx+cellx])   

    hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
    hist = np.hstack(hists)

    # transform to Hellinger kernel
    eps = 1e-7
    hist /= hist.sum() + eps
    hist = np.sqrt(hist)
    hist /= math.norm(hist) + eps

    return hist
Esempio n. 4
0
 def direction(self, img_data):
     i1, i2 = self.data_points
     p1 = img_data[i1]
     p2 = img_data[i2]
     u = p2 - p1
     u /= norm(u.x(), u.y())
     return u
Esempio n. 5
0
 def direction(self, img_data):
     i1, i2 = self.data_points
     p1 = img_data[i1]
     p2 = img_data[i2]
     u = p2 - p1
     u /= norm(u.x(), u.y())
     return u
Esempio n. 6
0
 def __trace(self, psi_vector):
     if len(self.__lines) == 0:
         self.__add_trace()
         return
     m = psi_vector - quaternion(*self.__lines[-1])
     if m.norm() >= self.__strictness:
         self.__add_trace()
Esempio n. 7
0
 def polygon(self, f=1):
     sx, sy = self.anchors[0]
     sw, sh = self.size
     S, C = math.norm((sx, sy), f)
     return [
         (sx + S * sh, sy + C * sh),
         (sx + C * sw, sy - S * sw),
         (sx - S * sh, sy - C * sh),
         (sx - C * sw, sy + S * sw),
     ]
Esempio n. 8
0
 def setstate(self, x1, y1, **args):
     self.x1 = x1
     self.y1 = y1
     self.dx = self.x1 - self.x
     self.dy = self.y1 - self.y
     self.slope = self.dy / self.dx
     self.d = math.length((self.dx, self.dy))
     self.dhat = self.dhatx, self.dhaty = math.norm((self.dx, self.dy))
     self.scale = view.scale(self.z)
     self.d0 = self.d * self.scale
Esempio n. 9
0
 def constrain(self, pos, j):
     if pos[1] < 0.0001:
         pos = pos[0], 0.0001
     if pos[0] < 0:
         pos = 0, pos[1]
     if math.dot(pos, (C30, -S30)) > 0:
         pos, _ = ptoline(pos, (S30, C30))
     a = math.length(pos)
     if a > 1 - self.r:
         pos = math.norm(pos, 1 - self.r)
     return pos
Esempio n. 10
0
 def mouseMoveEvent(self, event):
     params = parameters.instance
     pos = event.pos()
     x = pos.x()
     y = pos.y()
     if self.on_search:
         ns = norm(x, y)
         params.search_size = ns
         self.updateCursor(x, y, True)
         event.accept()
         return
     elif self.on_template:
         ns = max(abs(x), abs(y))
         params.template_size = ns
         self.updateCursor(x, y, False)
         event.accept()
         return
     QGraphicsItem.mouseMoveEvent(self, event)
Esempio n. 11
0
 def mouseMoveEvent(self, event):
     params = parameters.instance
     pos = event.pos()
     x = pos.x()
     y = pos.y()
     if self.on_search:
         ns = norm(x, y)
         params.search_size = ns
         self.updateCursor(x, y, True)
         event.accept()
         return
     elif self.on_template:
         ns = max(abs(x), abs(y))
         params.template_size = ns
         self.updateCursor(x, y, False)
         event.accept()
         return
     QGraphicsItem.mouseMoveEvent(self, event)
Esempio n. 12
0
 def norm(self, x, u, *, keepdim=False, dim=-1):
     return math.norm(x, u, keepdim=keepdim, dim=dim)
Esempio n. 13
0
 def polygon(self, f=1):
     sx, sy = self.anchors[0]
     dx, dy = math.norm((sx, sy))
     rs = [f * self.r * (1 / 2 if j % 2 else 1) for j in range(10)]
     return [(sx + r * dx * S + r * dy * C, sy - r * dx * C + r * dy * S)
             for r, (S, C) in zip(rs, math.CSround(10))]