def update_frame(val):
    
    global n     
    global previous_angle    
    
    angle = np.around(slider_rotation.val)
    shift = np.around(slider_translation.val)
    
    frame1 = generate_frame(angle, shift) # Slip simulation
    
    # Compute translation
    slipvector = NCC.normalized_cross_correlation(frame0, frame1)
        
    # Compute orientation
    (centroid_x, centroid_y, angle, Cov, lambda1, lambda2, 
     std_dev_x, std_dev_y, skew_x, skew_y,
     compactness1, compactness2, eccentricity1, eccentricity2) = IM.compute_orientation_and_shape_features(frame1)
    
    # Track rotation   
    current_angle, slip_angle, slip_angle_reference, n = IM.track_angle(reference_angle, previous_angle, angle, n)
 
    previous_angle = current_angle

    ###########
    # Plotting
    ###########
    ax = axes[1]
    ax.cla() # clear
    ax.imshow(frame1, cmap=cmap, vmin=0.001, vmax=1.0, interpolation='nearest')
    l3, l4 = plot_principal_axes_cov(centroid_x, centroid_y, Cov, UIBK_orange, ax)
    ax.set_title("Moving frame")
    ax.text(0.01, 1.0, text_template_angle%(current_angle, slip_angle), size=12, color=UIBK_orange)
    ax.text(0.01, 2.0, text_template_shift%(slipvector[0], slipvector[1]), size=12, color=UIBK_orange)
    plt.draw()
def update_frame(val):
    global n  
    global reference_angle    
    global previous_angle    
    
    reference_frameID = int(np.around(slider_reference_frame.val))
    current_frameID = int(np.around(slider_current_frame.val))

    frame0 = loadFrame(frameManager, reference_frameID, matrixID)
    frame1 = loadFrame(frameManager, current_frameID, matrixID)
    
    # Compute translation between reference frames
    slipvector = NCC.normalized_cross_correlation(frame0, frame1)
    
    
    # Compute orientation of reference frame
    (centroid_x0, centroid_y0, angle0, Cov0, lambda10, lambda20, 
     std_dev_x0, std_dev_y0, skew_x0, skew_y0,
     compactness10, compactness20, eccentricity10, eccentricity20) = IM.compute_orientation_and_shape_features(frame0)

    # Compute orientation of current frame
    features1 = IM.compute_orientation_and_shape_features(frame1)
    (centroid_x1, centroid_y1, angle1, Cov1, lambda11, lambda21, 
     std_dev_x1, std_dev_y1, skew_x1, skew_y1,
     compactness11, compactness21, eccentricity11, eccentricity21) = features1
    
    IM.report_shape_features("Frame %d" %current_frameID , features1)
    
    # Reset tracking if reference angle changed
    if abs(reference_angle-angle0) > 0.001: 
        reference_angle = angle0 # [0, 180)
        previous_angle = angle0 # [0, 360)
        slip_angle = 0 # (-∞, ∞)
        n = 0 # rotation carry
     
    # Track rotation 
    current_angle, slip_angle, slip_angle_reference, n = IM.track_angle(reference_angle, previous_angle, angle1, n)
    previous_angle = current_angle

    ###########
    # Plotting
    ###########
   
    # Reference frame
    plot_frame(axes[1], frame0, centroid_x0, centroid_y0, Cov0)
    
    # Current frame
    plot_frame(axes[2], frame1, centroid_x1, centroid_y1, Cov1)

    # Textbox
    bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=1.0)
    ax = axes[0]    
    ax.cla()
    ax.axis('off')
    ax.text(0.5, 0.5, text_template%(current_angle, slip_angle, slipvector[0], slipvector[1]), 
                 transform=ax.transAxes, ha="center", va="center", size=14, bbox=bbox_props)
    plt.draw()
def update_frame(val):

    global n
    global previous_angle

    angle = np.around(slider_rotation.val)
    shift = np.around(slider_translation.val)

    frame1 = generate_frame(angle, shift)  # Slip simulation

    # Compute translation
    slipvector = NCC.normalized_cross_correlation(frame0, frame1)

    # Compute orientation
    (centroid_x, centroid_y, angle, Cov, lambda1, lambda2, std_dev_x,
     std_dev_y, skew_x, skew_y, compactness1, compactness2, eccentricity1,
     eccentricity2) = IM.compute_orientation_and_shape_features(frame1)

    # Track rotation
    current_angle, slip_angle, slip_angle_reference, n = IM.track_angle(
        reference_angle, previous_angle, angle, n)

    previous_angle = current_angle

    ###########
    # Plotting
    ###########
    ax = axes[1]
    ax.cla()  # clear
    ax.imshow(frame1, cmap=cmap, vmin=0.001, vmax=1.0, interpolation='nearest')
    l3, l4 = plot_principal_axes_cov(centroid_x, centroid_y, Cov, UIBK_orange,
                                     ax)
    ax.set_title("Moving frame")
    ax.text(0.01,
            1.0,
            text_template_angle % (current_angle, slip_angle),
            size=12,
            color=UIBK_orange)
    ax.text(0.01,
            2.0,
            text_template_shift % (slipvector[0], slipvector[1]),
            size=12,
            color=UIBK_orange)
    plt.draw()
示例#4
0
        r_lambda2.append(lambda2)
        r_std_dev_x.append(std_dev_x)
        r_std_dev_y.append(std_dev_y)
        r_skew_x.append(skew_x)
        r_skew_y.append(skew_y)
        r_compactness1.append(compactness1)
        r_compactness2.append(compactness2)
        r_eccentricity1.append(eccentricity1)
        r_eccentricity2.append(eccentricity2)

    # Compute slip angle
    if active_cells1 > thresh_active_cells_rotation:
        # Track slip angle
        if IM.valid_frame(compactness2, eccentricity2, thresh_compactness,
                          thresh_eccentricity):
            current_angle, slip_angle, slip_angle_reference, n = IM.track_angle(
                reference_angle, previous_angle, angle, n)
            previous_angle = current_angle
            r_slipangle.append(slip_angle)
    else:
        r_slipangle.append(0.0)

r_slipvector = np.array(r_slipvector)
r_slipangle = np.array(r_slipangle)
r_centroid_x = np.array(r_centroid_x)
r_centroid_y = np.array(r_centroid_y)
r_angle = np.array(r_angle)
r_Cov = np.array(r_Cov)
r_lambda1 = np.array(r_lambda1)
r_lambda2 = np.array(r_lambda2)
r_std_dev_x = np.array(r_std_dev_x)
r_std_dev_y = np.array(r_std_dev_y)
        r_lambda2.append(lambda2)
        r_std_dev_x.append(std_dev_x)
        r_std_dev_y.append(std_dev_y)
        r_skew_x.append(skew_x)
        r_skew_y.append(skew_y)
        r_compactness1.append(compactness1)
        r_compactness2.append(compactness2)
        r_eccentricity1.append(eccentricity1)
        r_eccentricity2.append(eccentricity2)

    # Compute slip angle
    if active_cells1 > thresh_active_cells_rotation:
        # Track slip angle
        if IM.valid_frame(compactness2, eccentricity2, thresh_compactness, thresh_eccentricity):
            current_angle, slip_angle, slip_angle_reference, n = IM.track_angle(
                reference_angle, previous_angle, angle, n
            )
            previous_angle = current_angle
            r_slipangle.append(slip_angle)
    else:
        r_slipangle.append(0.0)


r_slipvector = np.array(r_slipvector)
r_slipangle = np.array(r_slipangle)
r_centroid_x = np.array(r_centroid_x)
r_centroid_y = np.array(r_centroid_y)
r_angle = np.array(r_angle)
r_Cov = np.array(r_Cov)
r_lambda1 = np.array(r_lambda1)
r_lambda2 = np.array(r_lambda2)
def update_frame(val):
    global n
    global reference_angle
    global previous_angle

    reference_frameID = int(np.around(slider_reference_frame.val))
    current_frameID = int(np.around(slider_current_frame.val))

    frame0 = loadFrame(frameManager, reference_frameID, matrixID)
    frame1 = loadFrame(frameManager, current_frameID, matrixID)

    # Compute translation between reference frames
    slipvector = NCC.normalized_cross_correlation(frame0, frame1)

    # Compute orientation of reference frame
    (centroid_x0, centroid_y0, angle0, Cov0, lambda10, lambda20, std_dev_x0,
     std_dev_y0, skew_x0, skew_y0, compactness10, compactness20,
     eccentricity10,
     eccentricity20) = IM.compute_orientation_and_shape_features(frame0)

    # Compute orientation of current frame
    features1 = IM.compute_orientation_and_shape_features(frame1)
    (centroid_x1, centroid_y1, angle1, Cov1, lambda11, lambda21, std_dev_x1,
     std_dev_y1, skew_x1, skew_y1, compactness11, compactness21,
     eccentricity11, eccentricity21) = features1

    IM.report_shape_features("Frame %d" % current_frameID, features1)

    # Reset tracking if reference angle changed
    if abs(reference_angle - angle0) > 0.001:
        reference_angle = angle0  # [0, 180)
        previous_angle = angle0  # [0, 360)
        slip_angle = 0  # (-∞, ∞)
        n = 0  # rotation carry

    # Track rotation
    current_angle, slip_angle, slip_angle_reference, n = IM.track_angle(
        reference_angle, previous_angle, angle1, n)
    previous_angle = current_angle

    ###########
    # Plotting
    ###########

    # Reference frame
    plot_frame(axes[1], frame0, centroid_x0, centroid_y0, Cov0)

    # Current frame
    plot_frame(axes[2], frame1, centroid_x1, centroid_y1, Cov1)

    # Textbox
    bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=1.0)
    ax = axes[0]
    ax.cla()
    ax.axis('off')
    ax.text(0.5,
            0.5,
            text_template %
            (current_angle, slip_angle, slipvector[0], slipvector[1]),
            transform=ax.transAxes,
            ha="center",
            va="center",
            size=14,
            bbox=bbox_props)
    plt.draw()