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()
Example #2
0
         "Compactness (contour)", "Eccentricity", "Eccentricity (squared)")

for i in frameIDS:

    # Relative timestamps in seconds
    timestamp = timestamps[i] - timestamps[startID]

    j = i - startID

    # Regrouping
    features = (r_centroid_x[j], r_centroid_y[j], r_angle[j], r_Cov[j],
                r_lambda1[j], r_lambda2[j], r_std_dev_x[j], r_std_dev_y[j],
                r_skew_x[j], r_skew_y[j], r_compactness1[j], r_compactness2[j],
                r_eccentricity1[j], r_eccentricity2[j])

    IM.report_shape_features("Frame " + str(i), features)
    print "Time: " + str(timestamp)
    print "Translation: [" + str(cumulative_slipvector[j][1]) + ", " + str(
        cumulative_slipvector[j][0]) + "]"
    print "Rotation: [" + str(cumulative_slipangle[j]) + "]"
'''
###########
# Plotting
###########
colormap=plt.get_cmap('gray')
#colormap=plt.get_cmap('YlOrRd_r')
#colormap = plt.get_cmap('afmhot')
colormap.set_under([0.0, 0.0, 0.0])
#colormap.set_under([0.3, 0.3, 0.3])
#colormap.set_under([1.0, 1.0, 1.0])
        r_centroid_y[j],
        r_angle[j],
        r_Cov[j],
        r_lambda1[j],
        r_lambda2[j],
        r_std_dev_x[j],
        r_std_dev_y[j],
        r_skew_x[j],
        r_skew_y[j],
        r_compactness1[j],
        r_compactness2[j],
        r_eccentricity1[j],
        r_eccentricity2[j],
    )

    IM.report_shape_features("Frame " + str(i), features)
    print "Time: " + str(timestamp)
    print "Translation: [" + str(cumulative_slipvector[j][1]) + ", " + str(cumulative_slipvector[j][0]) + "]"
    print "Rotation: [" + str(cumulative_slipangle[j]) + "]"

"""
###########
# Plotting
###########
colormap=plt.get_cmap('gray')
#colormap=plt.get_cmap('YlOrRd_r')
#colormap = plt.get_cmap('afmhot')
colormap.set_under([0.0, 0.0, 0.0])
#colormap.set_under([0.3, 0.3, 0.3])
#colormap.set_under([1.0, 1.0, 1.0])
frameManager.load_profile(profileName);
numFrames = frameManager.get_tsframe_count();

reference_frameID = 13
current_frameID = 13
matrixID = 1

frame0 = loadFrame(frameManager, reference_frameID, matrixID)

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

IM.report_shape_features("Initial frame", features)

reference_angle = angle # [0, 180)
previous_angle = angle # [0, 360)
slip_angle = 0 # (-∞, ∞)
n = 0 # rotation carry



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

#mpl.rcParams['text.usetex'] = True  # True, False
#text_template_angle = r'$\mathbf{ \phi: %.1f \quad \Delta \phi = %.1f} $'
#text_template_shift = r'$\mathbf{ \Delta x: %.1f, \quad \Delta y: %.1f} $'
    "img_test02.png",
    "img_test03.png",
    "img_test04.png",
    "img_test05.png",
    "img_test06.png")

frames = []
for name in filenames:
    frame = cv2.imread(name, cv2.CV_LOAD_IMAGE_GRAYSCALE)
    frames.append((name, frame))

for frame in frames:
    # Compute shape features and orientation
    features = IM.compute_orientation_and_shape_features(frame[1])
    # Report
    IM.report_shape_features(frame[0], features)

########################
# Load pressure profile
########################

profileName = os.path.abspath("slip_and_rotation_teapot_handle.dsa")
frameManager = framemanager_python.FrameManagerWrapper()
frameManager.load_profile(profileName)
frameID = 34
matrixID = 1

frame = np.copy(frameManager.get_tsframe(frameID, matrixID))
frame = np.uint8(frame /
                 (4096.0 / 255.0))  # scale to [0..255] and convert to uint8
#frame = cv2.normalize(frame, 0, 255, norm_type=cv2.NORM_MINMAX, dtype=cv2.cv.CV_8UC1); # Scale such that highest intensity is 255
    "img_test03.png",
    "img_test04.png",
    "img_test05.png",
    "img_test06.png",
)

frames = []
for name in filenames:
    frame = cv2.imread(name, cv2.CV_LOAD_IMAGE_GRAYSCALE)
    frames.append((name, frame))

for frame in frames:
    # Compute shape features and orientation
    features = IM.compute_orientation_and_shape_features(frame[1])
    # Report
    IM.report_shape_features(frame[0], features)


########################
# Load pressure profile
########################

profileName = os.path.abspath("slip_and_rotation_teapot_handle.dsa")
frameManager = framemanager_python.FrameManagerWrapper()
frameManager.load_profile(profileName)
frameID = 34
matrixID = 1

frame = np.copy(frameManager.get_tsframe(frameID, matrixID))
frame = np.uint8(frame / (4096.0 / 255.0))  # scale to [0..255] and convert to uint8
# frame = cv2.normalize(frame, 0, 255, norm_type=cv2.NORM_MINMAX, dtype=cv2.cv.CV_8UC1); # Scale such that highest intensity is 255
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()
frameManager.load_profile(profileName)
numFrames = frameManager.get_tsframe_count()

reference_frameID = 13
current_frameID = 13
matrixID = 1

frame0 = loadFrame(frameManager, reference_frameID, matrixID)

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

IM.report_shape_features("Initial frame", features)

reference_angle = angle  # [0, 180)
previous_angle = angle  # [0, 360)
slip_angle = 0  # (-∞, ∞)
n = 0  # rotation carry

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

#mpl.rcParams['text.usetex'] = True  # True, False
#text_template_angle = r'$\mathbf{ \phi: %.1f \quad \Delta \phi = %.1f} $'
#text_template_shift = r'$\mathbf{ \Delta x: %.1f, \quad \Delta y: %.1f} $'
#text_template_angle = 'phi: %.1f   dphi = %.1f'
#text_template_shift = 'dx: %.1f,   dy: %.1f'