コード例 #1
0
 def sigmoid(self):
     rb = -(self.src.shape[1] * np.tan(np.deg2rad(100 / 2))) / (
         np.tan(np.deg2rad(self.fov / 2)) * np.log(99e-8))
     ra = rb * np.log(99)
     return np.repeat(
         np.power(
             1 +
             np.exp(-(np.linalg.norm(self.uniform_grid, axis=2) - ra) / rb),
             -1), 2).reshape(self.uniform_grid.shape)
コード例 #2
0
    def __init__(self,
                 center=(0., 0.),
                 semi_major_axis=2.,
                 semi_minor_axis=1.,
                 angle=90.):
        self.center = center  # Center of the circle
        a = semi_major_axis
        b = semi_minor_axis
        xc = center[0]
        yc = center[1]
        angle = np.deg2rad(angle)

        #https://en.wikipedia.org/wiki/Ellipse
        A = a**2 * (np.sin(angle)**2) + b**2 * (np.cos(angle)**2)
        B = 2 * (b**2 - a**2) * np.sin(angle) * np.cos(angle)
        C = a**2 * (np.cos(angle)**2) + b**2 * (np.sin(angle)**2)
        D = -2 * A * xc - B * yc
        E = -B * xc - 2 * C * yc
        F = A * xc**2 + B * xc * yc + C * yc**2 - (a**2) * (b**2)

        self.a = A
        self.b = B
        self.c = C
        self.d = D
        self.e = E
        self.f = F

        self.update_conic_matrix()
コード例 #3
0
 def __init__(self):
     """ Definition of a simulated camera """
     self.cam = Camera()
     self.cam.set_K(fx=100, fy=100, cx=640, cy=480)
     self.cam.set_width_heigth(1280, 960)
     """ Initial camera pose looking stratight down into the plane model """
     self.cam.set_R_axisAngle(1.0, 0.0, 0.0, np.deg2rad(180))
     self.cam.set_t(0.0, 0.0, 1.5, frame='world')
     """ Plane for the control points """
     self.sph = Sphere(radius=0.5)
     self.sph.random_points(p=6, r=0.5, min_dist=0.001)
コード例 #4
0
ファイル: utils.py プロジェクト: Cubix651/neuralnetwork
def scale_and_rotate_mnist_image(image, angle_range=15.0, scale_range=0.1):
        angle = 2 * angle_range * np.random.random() - angle_range
        scale = 1 + 2 * scale_range * np.random.random() - scale_range

        tf_rotate = transform.SimilarityTransform(rotation=np.deg2rad(angle))
        tf_scale = transform.SimilarityTransform(scale=scale)
        tf_shift = transform.SimilarityTransform(translation=[-14, -14])
        tf_shift_inv = transform.SimilarityTransform(translation=[14, 14])

        image = transform.warp(image.reshape([28, 28]),
                               (tf_shift + tf_scale + tf_rotate + tf_shift_inv).inverse)
        return image.reshape([28*28])
コード例 #5
0
def scale_and_rotate_mnist_image(image, angle_range=15.0, scale_range=0.1):
    angle = 2 * angle_range * np.random.random() - angle_range
    scale = 1 + 2 * scale_range * np.random.random() - scale_range

    tf_rotate = transform.SimilarityTransform(rotation=np.deg2rad(angle))
    tf_scale = transform.SimilarityTransform(scale=scale)
    tf_shift = transform.SimilarityTransform(translation=[-14, -14])
    tf_shift_inv = transform.SimilarityTransform(translation=[14, 14])

    image = transform.warp(image.reshape(
        [28, 28]), (tf_shift + tf_scale + tf_rotate + tf_shift_inv).inverse)
    return image.reshape([28 * 28])
コード例 #6
0
    def __init__(self,
                 ref_energy,
                 energy_gain,
                 acc_max,
                 alpha_max_pd_enable=20.0,
                 pd_gain=None):

        # Set up the energy pumping controller
        self.en_ctrl = EnergyCtrl(ref_energy, energy_gain, acc_max)

        # Set up the PD controller
        cos_al_delta = np.cos(2. * np.pi - np.deg2rad(alpha_max_pd_enable))
        self.pd_enabled = lambda cos_al: cos_al > cos_al_delta
        pd_gain = pd_gain if pd_gain is not None else [-1.5, 25.0, -1.5, 2.5]
        self.pd_ctrl = PDCtrl(K=pd_gain)
コード例 #7
0
ファイル: autograd_test.py プロジェクト: oygx210/EMTG-1
a = 10.0
b = 8.0
c = 6.0

# set Euler angles relating BCF frame to PA frame (3-1-3)
# Note on comparisons with STK:
# The Body_Axes_Body_Fixed system was created as a "Fixed in Axes" type set of axes.
# The reference axes is principal axis frame.
# Theta1 corresponds to Euler Angle A
# Theta2 corresponds to Euler Angle B
# Theta3 corresponds to Euler Angle C
# However, all the signs of the angles need to be reversed because the rotations are going the other direction.
theta1_0 = -21.0  # deg
theta2_0 = -9.0  # deg
theta3_0 = -14.0  # deg
theta1_0rad = np.deg2rad(theta1_0)  # rad
theta2_0rad = np.deg2rad(theta2_0)
theta3_0rad = np.deg2rad(theta3_0)

# assume the theta's can vary linearly in time with constant rates
theta1dot_0 = 0.2  # deg/s
theta2dot_0 = 0.1  # deg/s
theta3dot_0 = 0.4  # deg/s
#theta1dot_0 = 0. # deg/s
#theta2dot_0 = 0. # deg/s
#theta3dot_0 = 0. # deg/s
theta1dot_0rad = np.deg2rad(theta1dot_0)  # rad/s
theta2dot_0rad = np.deg2rad(theta2dot_0)
theta3dot_0rad = np.deg2rad(theta3dot_0)

# calculate a point on that ellipsoid
コード例 #8
0
elif number_of_points == 5:
    import gdescent.hpoints_gradient5 as gd
elif number_of_points == 6:
    import gdescent.hpoints_gradient6 as gd

## Define a Display plane with random initial points
pl = CircularPlane()
pl.random(n=number_of_points, r=0.01, min_sep=0.01)

## CREATE A SIMULATED CAMERA
cam = Camera()
cam.set_K(fx=800, fy=800, cx=640 / 2., cy=480 / 2.)
cam.set_width_heigth(640, 480)

## DEFINE CAMERA POSE LOOKING STRAIGTH DOWN INTO THE PLANE MODEL
cam.set_R_axisAngle(1.0, 0.0, 0.0, np.deg2rad(180.0))
cam.set_t(0.0, -0.0, 0.5, frame='world')

#cam.set_R_axisAngle(1.0,  0.0,  0.0, np.deg2rad(140.0))
#cam.set_t(0.0,-1,1.0, frame='world')
#
r = 0.8
angle = 30
x = r * np.cos(np.deg2rad(angle))
z = r * np.sin(np.deg2rad(angle))
cam.set_t(0, x, z)
cam.set_R_mat(R_matrix_from_euler_t(0.0, 0, 0))
cam.look_at([0, 0, 0])

#cam.set_R_axisAngle(1.0,  0.0,  0.0, np.deg2rad(110.0))
#cam.set_t(0.0,-0.3,0.1, frame='world')
コード例 #9
0
elif number_of_points == 6:
    import gdescent.hpoints_gradient6 as gd

## Define a Display plane with random initial points
pl = CircularPlane()
pl.random(n=number_of_points, r=0.01, min_sep=0.01)

## CREATE A SIMULATED CAMERA
cam = Camera()
cam.set_K(fx=800, fy=800, cx=640 / 2., cy=480 / 2.)
cam.set_width_heigth(640, 480)

## DEFINE A SET OF CAMERA POSES IN DIFFERENT POSITIONS BUT ALWAYS LOOKING
# TO THE CENTER OF THE PLANE MODEL

cam.set_R_axisAngle(1.0, 0.0, 0.0, np.deg2rad(180.0))
cam.set_t(0.0, -0.0, 0.5, frame='world')

r = 0.8
angle = 90
x = r * np.cos(np.deg2rad(angle))
z = r * np.sin(np.deg2rad(angle))
cam.set_t(0, x, z)
cam.set_R_mat(R_matrix_from_euler_t(0.0, 0, 0))
cam.look_at([0, 0, 0])

max_deviation = 0.06
deviation_range = np.arange(0, max_deviation + 0.01, 0.01)

#Now we define a distribution of cameras on the space based on this plane
#An optional paremeter is de possible deviation from uniform points
コード例 #10
0
def test_deg2rad():
    fun = lambda x: 3.0 * np.deg2rad(x)
    check_grads(fun)(10.0 * npr.rand())
コード例 #11
0
ファイル: test_scalar_ops.py プロジェクト: HIPS/autograd
def test_deg2rad():
    fun = lambda x : 3.0 * np.deg2rad(x)
    check_grads(fun)(10.0*npr.rand())
コード例 #12
0
def svm_fn(*args):#kappa,amplitude):
    # wrapper function, using fixed uangle in degrees
    return sym_von_mises_function(np.deg2rad(uangle),*args)#kappa,amplitude)
コード例 #13
0
            break
        c = ax.imshow(imgr[i, :].reshape(npx, npy).T, origin='lower')
        div = make_axes_locatable(ax)
        cax = div.append_axes("right", size="10%", pad=0.05)
        cbar = pl.colorbar(c, cax=cax)
        ax.set_title(parn[i])
    return fig


if __name__ == "__main__":
    rh = 3 # half-light radius
    rho = 0.5 # minor/major axis ratio
    a = rh / np.sqrt(rho) # semi-major axis
    b = rh * np.sqrt(rho) # semi-minor axis
    
    theta = np.deg2rad(30)  # position angle (CCW from positive x-axis)
    x0 = 0.5  # center x
    y0 = -0.5  # center y
    ptrue = np.array([rho, theta, x0, y0])


    # --- Set up the galaxy and pixels -----
    minrad, maxrad, dlnr = 0.20, 28.0, np.log(2)
    lnradii = np.arange(np.log(minrad), np.log(maxrad), dlnr)
    lnradii = np.insert(lnradii, 0, -np.inf)
    radii = np.exp(lnradii)
    # n=4, r_h = 3.0
    amplitudes = [3.01569009,   7.003088  ,  15.02690983,  24.50030708,
                  38.70292664,  42.86139297,  38.57839966,  21.7422924,
                  10.47532463]
    amplitudes = np.array(amplitudes)
コード例 #14
0
number_of_points = 4

if number_of_points == 4:
    import gdescent.hpoints_gradient as gd
elif number_of_points == 5:
    import gdescent.hpoints_gradient5 as gd
elif number_of_points == 6:
    import gdescent.hpoints_gradient6 as gd

## CREATE A SIMULATED CAMERA
cam = Camera()
cam.set_K(fx=800, fy=800, cx=640, cy=480)
cam.set_width_heigth(960, 960)

## DEFINE CAMERA POSE LOOKING STRAIGTH DOWN INTO THE PLANE MODEL
cam.set_R_axisAngle(1.0, 0.0, 0.0, np.deg2rad(180.0))
cam.set_t(0.0, -0.0, 0.5, frame='world')

#cam.set_R_axisAngle(1.0,  0.0,  0.0, np.deg2rad(140.0))
#cam.set_t(0.0,-1,1.0, frame='world')
#
#r = 0.5
#angle = 10
#x = r*np.cos(np.deg2rad(angle))
#z = r*np.sin(np.deg2rad(angle))
#cam.set_t(0, x,z)
#cam.set_R_mat(R_matrix_from_euler_t(0.0,0,0))
#cam.look_at([0,0,0])

#cam.set_R_axisAngle(1.0,  0.0,  0.0, np.deg2rad(110.0))
#cam.set_t(0.0,-0.3,0.1, frame='world')
コード例 #15
0
for i, img in enumerate(imgs[:2]):
    kp, d = sift.detectAndCompute(img, None)
    descs.append(d)
    keypoints.append(kp)

matches = bfmatcher.knnMatch(descs[0], descs[1], k=10)
x_ = []
y_ = []
for i, dd in enumerate(descs):
    kps = keypoints[i]
    h, w, c = imgs[i].shape
    d_ = [d / np.linalg.norm(d) for d in dd[:N_points]]
    dkp_ = [
        list(d_[i]) + [(k.pt[0] - w / 2) / w, (k.pt[1] - h / 2) / h,
                       np.log(k.size),
                       np.deg2rad(k.angle)]
        for i, k in enumerate(kps[:N_points])
    ]
    x_.append([k.pt[0] for k in kps[:N_points]])
    y_.append([k.pt[1] for k in kps[:N_points]])
print([len(d) for d in dl])

if plot > 3:
    myplot = []
    for i in range(len(x_)):
        for j in range(len(x_[0])):
            x0, y0 = int(x_[0][j]), int(y_[0][j])
            x, y, _ = tuple(h_apply(H[0, i], (x0, y0, 1)))
            s = keypoints[0][j].size
            octave, layer, scale = unpackSIFTOctave(keypoints[0][j].octave)
            theta = keypoints[0][j].angle
コード例 #16
0
def test_deg2rad():
    fun = lambda x : 3.0 * np.deg2rad(x)
    d_fun = grad(fun)
    check_grads(fun, 10.0*npr.rand())
    check_grads(d_fun, 10.0*npr.rand())
コード例 #17
0
ファイル: test_scalar_ops.py プロジェクト: zaxtax/autograd
def test_deg2rad():
    fun = lambda x : 3.0 * np.deg2rad(x)
    d_fun = grad(fun)
    check_grads(fun, 10.0*npr.rand())
    check_grads(d_fun, 10.0*npr.rand())
コード例 #18
0
if number_of_points == 4:
    import gdescent.hpoints_gradient as gd
elif number_of_points == 5:
    import gdescent.hpoints_gradient5 as gd
elif number_of_points == 6:
    import gdescent.hpoints_gradient6 as gd

## Define a Display plane
pl = CircularPlane()
pl.random(n=number_of_points, r=0.010, min_sep=0.001)

objectPoints_start = pl.get_points()
############################################################################
#Always the same starting points
#4 points: An ideal square
x1 = 0.15 * np.cos(np.deg2rad(45))
y1 = 0.15 * np.sin(np.deg2rad(45))
objectPoints_start = np.array([[x1, -x1, -x1, x1], [y1, y1, -y1, -y1],
                               [
                                   0.,
                                   0.,
                                   0.,
                                   0.,
                               ], [
                                   1.,
                                   1.,
                                   1.,
                                   1.,
                               ]])

##5 Points: a square and one point in the middle.