def test_active_matrices_from_extrinsic_euler_angles_1dim():
    random_state = np.random.RandomState(8384)
    e = random_state.randn(10, 3)
    Rs = pbr.active_matrices_from_extrinsic_euler_angles(2, 1, 0, e)
    for i in range(len(e)):
        Ri = pr.active_matrix_from_extrinsic_euler_zyx(e[i])
        assert_array_almost_equal(Rs[i], Ri)
def test_active_matrices_from_extrinsic_euler_angles_1dim_output_variable():
    random_state = np.random.RandomState(8385)
    e = random_state.randn(10, 3)
    Rs = np.empty((10, 3, 3))
    pbr.active_matrices_from_extrinsic_euler_angles(2, 1, 0, e, out=Rs)
    for i in range(len(e)):
        Ri = pr.active_matrix_from_extrinsic_euler_zyx(e[i])
        assert_array_almost_equal(Rs[i], Ri)
def test_active_matrices_from_extrinsic_euler_angles_0dims():
    random_state = np.random.RandomState(8383)
    e = random_state.randn(3)
    R = pbr.active_matrices_from_extrinsic_euler_angles(2, 1, 0, e)
    R2 = pr.active_matrix_from_extrinsic_euler_zyx(e)
    assert_array_almost_equal(R, R2)
예제 #4
0
canvas = cv2.imread(r'input\bird.png')
canvas_y, canvas_x, _ = canvas.shape
# canvas = np.zeros((canvas_y, canvas_x, 3), dtype=np.uint8)

# 读取纸张
paper = cv2.imread(r'input\paper.png')
jmax, imax, _ = paper.shape

# 纸张放在画布的初始位置,这里定位中心,并建立起纸张坐标->画布坐标的转换关系
dx, dy = (canvas_x - imax)//2, (canvas_y-jmax)//2
def paper2canvas(x, y):
    return x+dx, y+dy

# 通过欧拉角获得旋转的四元数
z_rot, y_rot, x_rot = 30, 30, 15
rot_matrix = active_matrix_from_extrinsic_euler_zyx(((z_rot/180*np.pi), (y_rot/180*np.pi), (x_rot/180*np.pi)))
qs = quaternion_slerp_batch(q_id, quaternion_from_matrix(rot_matrix), np.linspace(0, 1, n_steps))

def do_rot(v, t):
    '''对t时刻时的向量(点)v做旋转变换'''
    return q_prod_vector(qs[t], v)

# 除了旋转之外,还会有平移
trans_start, trans_max = (0, 0, 0), (0, 0, 1600)
trans = np.linspace(trans_start, trans_max, n_steps)
def do_trans(v, t):
    return (v[0]+trans[t][0]), (v[1]+trans[t][1]), (v[2]+trans[t][2])

# 透视的话需要知道眼睛的位置
eye = (imax//2, jmax//2, -1600)
def proj(v):