Exemplo n.º 1
0
    def __init__(self, dataset_path=None, custom_parser=None):
        self.sequences = []
        if custom_parser is None:
            assert dataset_path, \
                    "If a custom parser is not given, dataset_path is required"
        try:
            if custom_parser is not None:
                self.action_labels, \
                        self.joint_labels, \
                        self.viewpoint_labels,\
                        self.sequences = custom_parser(dataset_path)
            else:
                # Standard parser
                filename = '%s/annotations.dat.gz' % dataset_path
                fid = gzip.open(filename, 'r')
                gz_header = fid.readline()
                std_dat_parser(self, fid)
                fid.close()

            if BaseParser.compute_dataset_info:
                printcn(HEADER, '## Info on dataset "%s" ##' % dataset_path)
                printcn(OKBLUE, '  Average number of frames: %.0f' % \
                        BaseParser.avg_num_frames)
                printcn(
                    OKBLUE, '  Min pose values on X-Y-Z: {}'.format(
                        BaseParser.pose_min))
                printcn(
                    OKBLUE, '  Max pose values on X-Y-Z: {}'.format(
                        BaseParser.pose_max))

        except Exception as e:
            print('Catch exception in Annotation class: ' + str(e))
Exemplo n.º 2
0
def show(x, gray_scale=False, jet_cmap=False, filename=None):
    """ Show 'x' as an image on the screen.
    """
    if jet_cmap is False:
        img = data_to_image(x, gray_scale=gray_scale)
    else:
        if plt is None:
            printcn(WARNING, 'pyplot not defined!')
            return
        cmap = plt.cm.jet
        norm = plt.Normalize(vmin=x.min(), vmax=x.max())
        img = cmap(norm(x))
    if filename:
        img.save(filename)
    else:
        img.show()
Exemplo n.º 3
0
def draw(x=None,
         skels=[],
         bboxes=[],
         bbox_color='g',
         abs_pos=False,
         plot3d=False,
         single_window=False,
         figsize=(16, 9),
         axis='on',
         facecolor='white',
         azimuth=65,
         dpi=100,
         filename=None,
         predicted=False):

    # Configure the plotting environment
    if plt is None:
        printcn(WARNING, 'pyplot not defined!')
        return
    """ Plot 'x' and draw over it the skeletons and the bounding boxes.
    """
    img = data_to_image(x)
    if abs_pos:
        w = None
        h = None
    else:
        w, h = img.size

    def add_subimage(f, subplot, img):
        ax = f.add_subplot(subplot)
        plt.imshow(img, zorder=-1)
        return ax

    fig = [plt.figure(figsize=figsize)]
    ax = []

    if plot3d:
        if single_window:
            ax.append(add_subimage(fig[0], 121, img))
            ax.append(fig[0].add_subplot(122, projection='3d'))
        else:
            ax.append(add_subimage(fig[0], 111, img))
            fig.append(plt.figure(figsize=figsize))
            ax.append(fig[1].add_subplot(111, projection='3d'))
    else:
        ax.append(add_subimage(fig[0], 111, img))

    plt.axis(axis)

    # Plotting skeletons if not None
    if skels is not None:
        if isinstance(skels, list) or len(skels.shape) == 3:
            for s in skels:
                plot_skeleton_2d(ax[0], s, h=h, w=w, predicted=predicted)
            if plot3d:
                plot_3d_pose(s, subplot=ax[-1], azimuth=azimuth)
        else:
            plot_skeleton_2d(ax[0], skels, h=h, w=w, predicted=predicted)
            if plot3d:
                plot_3d_pose(skels, subplot=ax[-1], azimuth=azimuth)

    # Plotting bounding boxes if not None
    if bboxes is not None:
        if isinstance(bboxes, list) or len(bboxes.shape) == 3:
            for b, c in zip(bboxes, bbox_color):
                _plot_bbox(ax[0], b, h=h, w=w, c=c, lw=4)
        else:
            _plot_bbox(ax[0], bboxes, h=h, w=w, c=bbox_color, lw=4)

    if filename:
        fig[0].savefig(filename,
                       bbox_inches='tight',
                       pad_inches=0,
                       facecolor=facecolor,
                       dpi=dpi)
        if plot3d and (single_window is False):
            fig[-1].savefig(filename + '.eps',
                            bbox_inches='tight',
                            pad_inches=0)
    else:
        plt.show()

    for i in range(len(fig)):
        plt.close(fig[i])
Exemplo n.º 4
0
from PIL import Image

from deephar.utils.io import WARNING
from deephar.utils.io import FAIL
from deephar.utils.io import printcn

from deephar.utils.pose import pa16j2d
from deephar.utils.pose import pa17j3d
from deephar.utils.pose import pa20j3d
from deephar.utils.colors import hex_colors

try:
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
except Exception as e:
    printcn(FAIL, str(e))
    plt = None


def data_to_image(x, gray_scale=False):
    """ Convert 'x' to a RGB Image object.

    # Arguments
        x: image in the format (num_cols, num_rows, 3) for RGB images or
            (num_cols, num_rows) for gray scale images. If None, return a
            light gray image with size 100x100.
        gray_scale: convert the RGB color space to a RGB gray scale space.
    """

    if x is None:
        x = 224 * np.ones((100, 100, 3), dtype=np.uint8)
Exemplo n.º 5
0
def draw(x=None,
         skels=None,
         bboxes=None,
         abs_pos=False,
         plot3d=False,
         single_window=False,
         figsize=(16, 9),
         axis='on',
         azimuth=65,
         filename=None):

    # Configure the ploting environment
    if plt is None:
        printcn(WARNING, 'pyplot not defined!')
        return
    """ Plot 'x' and draw over it the skeletons and the bounding boxes.
    """
    img = data_to_image(x)
    if abs_pos:
        w = None
        h = None
    else:
        w, h = img.size

    def add_subimage(f, subplot, img):
        ax = f.add_subplot(subplot)
        plt.imshow(img, zorder=-1)
        return ax

    fig = [plt.figure(figsize=figsize)]
    ax = []

    if plot3d:
        if single_window:
            ax.append(add_subimage(fig[0], 121, img))
            ax.append(fig[0].add_subplot(122, projection='3d'))
        else:
            ax.append(add_subimage(fig[0], 111, img))
            fig.append(plt.figure(figsize=figsize))
            ax.append(fig[1].add_subplot(111, projection='3d'))
    else:
        ax.append(add_subimage(fig[0], 111, img))

    plt.axis(axis)

    if isinstance(skels, list):
        assert len(skels) == 2, 'Only two skeletons are supported'
        _plot_skeleton_2d(ax[0], skels[0], h=h, w=w, joints=True, links=False)
        _plot_skeleton_2d(ax[0], skels[1], h=h, w=w, joints=False, links=True)
        if plot3d:
            plot_3d_pose(skels[0],
                         subplot=ax[-1],
                         color=5 * ['k'],
                         azimuth=azimuth)
            plot_3d_pose(skels[1], subplot=ax[-1], azimuth=azimuth)

    elif isinstance(skels, np.ndarray):
        _plot_skeleton_2d(ax[0], skels, h=h, w=w)
        if plot3d:
            plot_3d_pose(skels, subplot=ax[-1], azimuth=azimuth)

    # if isinstance(bboxes, list):
    # for b in bboxes:
    # _plot_bbox(ax[0], b, 'k')
    # elif isinstance(bboxes, np.ndarray):
    # _plot_bbox(ax[0], bboxes, 'k')
    if bboxes is not None:
        _plot_bbox(ax[0], bboxes, h=h, w=w)

    if filename:
        fig[0].savefig(filename, bbox_inches='tight', pad_inches=0)
        if plot3d and (single_window is False):
            fig[-1].savefig(filename + '.eps',
                            bbox_inches='tight',
                            pad_inches=0)
    else:
        plt.show()

    for i in range(len(fig)):
        plt.close(fig[i])