Esempio n. 1
0
def find_cool_images(filename):
    """

    :param filenames: one string or a list of strings
    :return:
    """
    print('Opening file: %s' % filename)
    f = h5py.File(filename, "r")

    times = np.array(f['/timestamp'].value)

    time_post2_grasping = float(f["time_post2_grasping"].value)
    index_time_post2_grasping = np.argmin(
        np.abs(times -
               time_post2_grasping))  # Find index corresponding to timestamp

    compressed_kinectA = f['/color_image_KinectA'].value[
        index_time_post2_grasping]
    KinectA_color_time_post2_grasping = np.array(
        ig.uncompress(compressed_kinectA))

    compressed_kinectB = f['/color_image_KinectB'].value[
        index_time_post2_grasping]
    KinectB_color_time_post2_grasping = np.array(
        ig.uncompress(compressed_kinectB))

    compressed_GelSightA = f['/GelSightA_image'].value[
        index_time_post2_grasping]
    GelSightA_image_time_post2_grasping = np.array(
        ig.uncompress(compressed_GelSightA))

    compressed_GelSightB = f['/GelSightB_image'].value[
        index_time_post2_grasping]
    GelSightB_image_time_post2_grasping = np.array(
        ig.uncompress(compressed_GelSightB))

    fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
    ax1.imshow(KinectA_color_time_post2_grasping)
    ax2.imshow(KinectB_color_time_post2_grasping)
    ax3.imshow(GelSightA_image_time_post2_grasping)
    ax4.imshow(GelSightB_image_time_post2_grasping)
    ax1.axis('off')
    ax2.axis('off')
    ax3.axis('off')
    ax4.axis('off')
    plt.draw()
    # plt.ion()
    plt.show()
Esempio n. 2
0
def set_label(path, filenames):
    """

    :param filenames: one string or a list of strings
    :return:
    """
    if isinstance(filenames, basestring):
        filename = [filenames]  # only a string is convert to a list

    for filename in filenames:
        path_to_file = path + filename

        print('Opening file: %s' % path_to_file)
        f = h5py.File(path_to_file, "r+")

        times = np.array(f['/timestamp'].value)

        time_pre_grasping = float(f["time_pre_grasping"].value)
        index_time_pre_grasping = np.argmin(
            np.abs(times -
                   time_pre_grasping))  # Find index corresponding to timestamp

        GelSightA_image_time_pre_grasping = np.array(
            ig.uncompress(
                f['/GelSightA_image'].value[index_time_pre_grasping]))
        GelSightB_image_time_pre_grasping = np.array(
            ig.uncompress(
                f['/GelSightB_image'].value[index_time_pre_grasping]))

        KinectA_color_time_pre_grasping = np.array(
            ig.uncompress(
                f['/color_image_KinectA'].value[index_time_pre_grasping]))
        KinectB_color_time_pre_grasping = np.array(
            ig.uncompress(
                f['/color_image_KinectB'].value[index_time_pre_grasping]))

        plt.imshow(KinectA_color_time_pre_grasping)
        plt.axis('off')
        plt.draw()
        plt.ion()
        plt.show()

        str(f['object_name'].value)

        print(
            "Does the name of the object correspond to the one printed below? [y/n]"
        )
        print(str(f['object_name'].value))
        done = False
        while not done:
            c = grip_and_record.getch.getch()
            if c:
                if c in ['n']:
                    name = input("Enter the correct name: ")
                    data = f['object_name']
                    data[...] = np.asarray([name])
                    done = True
                elif c in ['y']:
                    done = True

        f.flush()
        f.close()
        plt.close()
Esempio n. 3
0
def find_cool_images(path, filenames):
    """

    :param filenames: one string or a list of strings
    :return:
    """
    if isinstance(filenames, basestring):
        filename = [filenames]  # only a string is convert to a list

    for filename in filenames:
        path_to_file = path + filename

        print('Opening file: %s' % path_to_file)
        f = h5py.File(path_to_file, "r")

        times = np.array(f['/timestamp'].value)

        time_post2_grasping = float(f["time_at_grasping"].value)
        index_time_post2_grasping = np.argmin(
            np.abs(
                times -
                time_post2_grasping))  # Find index corresponding to timestamp

        compressed_kinectA = f['/color_image_KinectA'].value[
            index_time_post2_grasping]
        KinectA_color_time_post2_grasping = np.array(
            ig.uncompress(compressed_kinectA))

        compressed_kinectB = f['/color_image_KinectB'].value[
            index_time_post2_grasping]
        KinectB_color_time_post2_grasping = np.array(
            ig.uncompress(compressed_kinectB))

        kinectA_depth = f['/depth_image_KinectA'].value[
            index_time_post2_grasping]
        KinectA_depth_time_post2_grasping = np.array(kinectA_depth).squeeze()

        kinectB_depth = f['/depth_image_KinectB'].value[
            index_time_post2_grasping]
        KinectB_depth_time_post2_grasping = np.array(kinectB_depth).squeeze()

        compressed_GelSightA = f['/GelSightA_image'].value[
            index_time_post2_grasping]
        GelSightA_image_time_post2_grasping = np.array(
            ig.uncompress(compressed_GelSightA))

        compressed_GelSightB = f['/GelSightB_image'].value[
            index_time_post2_grasping]
        GelSightB_image_time_post2_grasping = np.array(
            ig.uncompress(compressed_GelSightB))

        # fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
        # ax1.imshow(KinectA_color_time_at_grasping)
        # ax2.imshow(KinectB_color_time_at_grasping)
        # ax3.imshow(GelSightA_image_time_at_grasping)
        # ax4.imshow(GelSightB_image_time_at_grasping)
        # ax1.axis('off')
        # ax2.axis('off')
        # ax3.axis('off')
        # ax4.axis('off')
        # plt.draw()
        # plt.ion()
        # plt.show()
        #
        # print("Is it a cool image? [y/n]")
        # done = False
        # cool = False
        # while not done:
        #     c = grip_and_record.getch.getch()
        #     if c:
        #         if c in ['n']:
        #             cool = False
        #             done = True
        #         elif c in ['y']:
        #             cool = True
        #             done = True

        path_cool = "/home/manu/ros_ws/src/manu_research/data/test_figure/"
        file = open(path_cool + filename[:-5] + '_GelSightA_at.jpeg', 'w')
        file.write(str(compressed_GelSightA))
        file.close()
        time.sleep(0.5)
        file = open(path_cool + filename[:-5] + '_GelSightB_at.jpeg', 'w')
        file.write(str(compressed_GelSightB))
        file.close()
        time.sleep(0.5)
        file = open(path_cool + filename[:-5] + '_kinectA_at.jpeg', 'w')
        file.write(str(compressed_kinectA))
        file.close()
        time.sleep(0.5)
        file = open(path_cool + filename[:-5] + '_kinectB_at.jpeg', 'w')
        file.write(str(compressed_kinectB))
        file.close()

        fig = plt.figure()
        print(KinectA_depth_time_post2_grasping.shape)
        KinectA_depth_time_post2_grasping = 1024 * (
            KinectA_depth_time_post2_grasping >
            1024) + KinectA_depth_time_post2_grasping * (
                KinectA_depth_time_post2_grasping < 1024)
        plt.imshow(KinectA_depth_time_post2_grasping, cmap='gray')
        plt.show()
        import scipyplot as spp
        spp.save2file(fig=fig, nameFile='depth_image_KinectA_at')

        fig = plt.figure()
        KinectB_depth_time_post2_grasping = 1024 * (
            KinectB_depth_time_post2_grasping >
            1024) + KinectB_depth_time_post2_grasping * (
                KinectB_depth_time_post2_grasping < 1024)
        plt.imshow(KinectB_depth_time_post2_grasping, cmap='gray')
        plt.show()
        spp.save2file(fig=fig, nameFile='depth_image_KinectB_at')
Esempio n. 4
0
def set_label(path, filenames):
    """

    :param filenames: one string or a list of strings
    :return:
    """
    if isinstance(filenames, basestring):
        filename = [filenames]  # only a string is convert to a list

    for filename in filenames:
        path_to_file = path + filename

        print('Opening file: %s' % path_to_file)
        f = h5py.File(path_to_file, "r")

        n_steps = int(f['n_steps'].value)

        # times = []
        # for i in tqdm(range(1, n_steps)):
        #     id = '/step_%012d' % i
        #     times.append(f[id + '/timestamp'].value)
        # times = np.array(times)

        times = np.array(f['/timestamp'].value)

        time_pre_grasping = float(f["time_pre_grasping"].value)
        index_time_pre_grasping = np.argmin(
            np.abs(times - time_pre_grasping))  # Find index corresponding to timestamp

        GelSightA_image_time_pre_grasping = np.array(
            ig.uncompress(f['/GelSightA_image'].value[index_time_pre_grasping]))
        GelSightB_image_time_pre_grasping = np.array(
            ig.uncompress(f['/GelSightB_image'].value[index_time_pre_grasping]))

        time_post2_grasping = float(f["time_post2_grasping"].value)
        index_time_post2_grasping = np.argmin(
            np.abs(times - time_post2_grasping))  # Find index corresponding to timestamp
        KinectA_color_time_post2_grasping = np.array(
            ig.uncompress(f['/color_image_KinectA'].value[index_time_post2_grasping]))
        KinectB_color_time_post2_grasping = np.array(
            ig.uncompress(f['/color_image_KinectB'].value[index_time_post2_grasping]))
        GelSightA_image_time_post2_grasping = np.array(
            ig.uncompress(f['/GelSightA_image'].value[index_time_post2_grasping]))
        GelSightB_image_time_post2_grasping = np.array(
            ig.uncompress(f['/GelSightB_image'].value[index_time_post2_grasping]))

        fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
        ax1.imshow(KinectA_color_time_post2_grasping)
        ax2.imshow(KinectB_color_time_post2_grasping)
        ax3.imshow(GelSightA_image_time_post2_grasping)
        ax4.imshow(GelSightB_image_time_post2_grasping)
        ax1.axis('off')
        ax2.axis('off')
        ax3.axis('off')
        ax4.axis('off')
        plt.draw()
        plt.ion()
        plt.show()

        print("Is the robot holding the object in its gripper? [y/n]")
        done = False
        while not done:
            c = grip_and_record.getch.getch()
            if c:
                if c in ['n']:
                    is_gripping = False
                    done = True
                elif c in ['y']:
                    is_gripping = True
                    done = True

        # TODO: check if folder exists, if not create
        path_0 = "/home/manu/ros_ws/src/manu_research/data/"
        file = open(path_0 + 'labels/' + filename[:-4] + 'txt', 'w')
        file.write(str(is_gripping))
        file.close()

        file = h5py.File(path_0 + "for_Andrew/" + filename, "w")
        file.create_dataset("GelSightA_image_pre_gripping", data=GelSightA_image_time_pre_grasping)
        file.create_dataset("GelSightB_image_pre_gripping", data=GelSightB_image_time_pre_grasping)
        file.create_dataset("GelSightA_image_post_gripping", data=GelSightA_image_time_post2_grasping)
        file.create_dataset("GelSightB_image_post_gripping", data=GelSightB_image_time_post2_grasping)
        file.create_dataset("is_gripping", data=np.asarray([is_gripping]))
        file.close()

        f.close()

        plt.close()
def find_cool_images(path, filenames):
    """

    :param filenames: one string or a list of strings
    :return:
    """
    if isinstance(filenames, basestring):
        filename = [filenames]  # only a string is convert to a list

    for filename in filenames:
        path_to_file = path + filename

        print('Opening file: %s' % path_to_file)
        f = h5py.File(path_to_file, "r")

        times = np.array(f['/timestamp'].value)

        time_at_grasping = float(f["time_at_grasping"].value)
        index_time_at_grasping = np.argmin(
            np.abs(times -
                   time_at_grasping))  # Find index corresponding to timestamp

        compressed_kinectA = f['/color_image_KinectA'].value[
            index_time_at_grasping]
        KinectA_color_time_at_grasping = np.array(
            ig.uncompress(compressed_kinectA))

        compressed_kinectB = f['/color_image_KinectB'].value[
            index_time_at_grasping]
        KinectB_color_time_at_grasping = np.array(
            ig.uncompress(compressed_kinectB))

        compressed_GelSightA = f['/GelSightA_image'].value[
            index_time_at_grasping]
        GelSightA_image_time_at_grasping = np.array(
            ig.uncompress(compressed_GelSightA))

        compressed_GelSightB = f['/GelSightB_image'].value[
            index_time_at_grasping]
        GelSightB_image_time_at_grasping = np.array(
            ig.uncompress(compressed_GelSightB))

        fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
        ax1.imshow(KinectA_color_time_at_grasping)
        ax2.imshow(KinectB_color_time_at_grasping)
        ax3.imshow(GelSightA_image_time_at_grasping)
        ax4.imshow(GelSightB_image_time_at_grasping)
        ax1.axis('off')
        ax2.axis('off')
        ax3.axis('off')
        ax4.axis('off')
        plt.draw()
        plt.ion()
        plt.show()

        print("Is it a cool image? [y/n]")
        done = False
        cool = False
        while not done:
            c = grip_and_record.getch.getch()
            if c:
                if c in ['n']:
                    cool = False
                    done = True
                elif c in ['y']:
                    cool = True
                    done = True

        if cool:
            path_cool = "/home/manu/ros_ws/src/manu_research/data/cool_images/"
            file = open(path_cool + filename[:-5] + '_GelSightA.jpeg', 'w')
            file.write(str(compressed_GelSightA))
            file.close()
            time.sleep(0.5)
            file = open(path_cool + filename[:-5] + '_GelSightB.jpeg', 'w')
            file.write(str(compressed_GelSightB))
            file.close()

        plt.close()