예제 #1
0
파일: data.py 프로젝트: BoAdBo/AlphaPose
def gensample(annot, idx, chg=None, sampletype='default', extra_args=None):
    img_in = ref.loadimg(annot, idx)
    if sampletype == 'default':
        return gendefault(annot, idx, img_in, chg)
    elif sampletype == 'detect':
        return gendetect(annot, idx, img_in, chg)
    elif sampletype == 'cascade':
        return gencascade(annot, idx, img_in, chg, extra_args)
예제 #2
0
def gensample(annot, idx, chg=None, sampletype='default', extra_args=None):
    img_in = ref.loadimg(annot, idx)
    if sampletype == 'default':
        return gendefault(annot, idx, img_in, chg)
    elif sampletype == 'detect':
        return gendetect(annot, idx, img_in, chg)
    elif sampletype == 'cascade':
        return gencascade(annot, idx, img_in, chg, extra_args)
예제 #3
0
파일: img.py 프로젝트: BoAdBo/AlphaPose
def sample_with_skeleton(annot, idx, preds, res=None):

    # Load image and basic info
    ds = annot.attrs['name']
    img = ref.loadimg(annot, idx)
    c = annot['center'][idx]
    s = annot['scale'][idx]
    if res is None:
        res = [256, 256]

    # Skeleton colors
    colors = [(255, 0, 0),          # Upper arm (left)
              (255, 100, 100),      # Lower arm (left)
              (0, 0, 255),          # Upper arm (right)
              (100, 100, 255),      # Lower arm (right)
              (100, 255, 100),      # Head/neck/face
              (255, 75, 0),        # Upper leg (left)
              (255, 175, 100),      # Lower leg (left)
              (0, 75, 255),        # Upper leg (right)
              (100, 175, 255)       # Lower leg (right)
              ]

    # Draw arms
    draw.limb(img, preds[ref.parts[ds].index('lsho')], preds[ref.parts[ds].index('lelb')], colors[0], 5 * s)
    draw.limb(img, preds[ref.parts[ds].index('lwri')], preds[ref.parts[ds].index('lelb')], colors[1], 5 * s)
    draw.limb(img, preds[ref.parts[ds].index('rsho')], preds[ref.parts[ds].index('relb')], colors[2], 5 * s)
    draw.limb(img, preds[ref.parts[ds].index('rwri')], preds[ref.parts[ds].index('relb')], colors[3], 5 * s)

    if ds == 'mpii':
        # MPII
        # Draw head
        draw.circle(img, preds[ref.parts[ds].index('head')], colors[4], 5 * s)
        draw.circle(img, preds[ref.parts[ds].index('neck')], colors[4], 5 * s)

        # Draw legs
        draw.limb(img, preds[ref.parts[ds].index('lhip')], preds[ref.parts[ds].index('lkne')], colors[5], 5 * s)
        draw.limb(img, preds[ref.parts[ds].index('lank')], preds[ref.parts[ds].index('lkne')], colors[6], 5 * s)
        draw.limb(img, preds[ref.parts[ds].index('rhip')], preds[ref.parts[ds].index('rkne')], colors[7], 5 * s)
        draw.limb(img, preds[ref.parts[ds].index('rank')], preds[ref.parts[ds].index('rkne')], colors[8], 5 * s)

    elif ds == 'flic':
        # FLIC
        # Draw face
        draw.circle(img, preds[ref.parts[ds].index('leye')], colors[4], 3 * s)
        draw.circle(img, preds[ref.parts[ds].index('reye')], colors[4], 3 * s)
        draw.circle(img, preds[ref.parts[ds].index('nose')], colors[4], 3 * s)

        # Draw hips
        draw.circle(img, preds[ref.parts[ds].index('lhip')], colors[5], 5 * s)
        draw.circle(img, preds[ref.parts[ds].index('rhip')], colors[7], 5 * s)

    return crop(img, c, s, res)
예제 #4
0
def sample_with_skeleton(annot, idx, preds, res=None):

    # Load image and basic info
    ds = annot.attrs['name']
    img = ref.loadimg(annot, idx)
    c = annot['center'][idx]
    s = annot['scale'][idx]
    if res is None:
        res = [256, 256]

    # Skeleton colors
    colors = [
        (255, 0, 0),  # Upper arm (left)
        (255, 100, 100),  # Lower arm (left)
        (0, 0, 255),  # Upper arm (right)
        (100, 100, 255),  # Lower arm (right)
        (100, 255, 100),  # Head/neck/face
        (255, 75, 0),  # Upper leg (left)
        (255, 175, 100),  # Lower leg (left)
        (0, 75, 255),  # Upper leg (right)
        (100, 175, 255)  # Lower leg (right)
    ]

    # Draw arms
    draw.limb(img, preds[ref.parts[ds].index('lsho')],
              preds[ref.parts[ds].index('lelb')], colors[0], 5 * s)
    draw.limb(img, preds[ref.parts[ds].index('lwri')],
              preds[ref.parts[ds].index('lelb')], colors[1], 5 * s)
    draw.limb(img, preds[ref.parts[ds].index('rsho')],
              preds[ref.parts[ds].index('relb')], colors[2], 5 * s)
    draw.limb(img, preds[ref.parts[ds].index('rwri')],
              preds[ref.parts[ds].index('relb')], colors[3], 5 * s)

    if ds == 'mpii':
        # MPII
        # Draw head
        draw.circle(img, preds[ref.parts[ds].index('head')], colors[4], 5 * s)
        draw.circle(img, preds[ref.parts[ds].index('neck')], colors[4], 5 * s)

        # Draw legs
        draw.limb(img, preds[ref.parts[ds].index('lhip')],
                  preds[ref.parts[ds].index('lkne')], colors[5], 5 * s)
        draw.limb(img, preds[ref.parts[ds].index('lank')],
                  preds[ref.parts[ds].index('lkne')], colors[6], 5 * s)
        draw.limb(img, preds[ref.parts[ds].index('rhip')],
                  preds[ref.parts[ds].index('rkne')], colors[7], 5 * s)
        draw.limb(img, preds[ref.parts[ds].index('rank')],
                  preds[ref.parts[ds].index('rkne')], colors[8], 5 * s)

    elif ds == 'flic':
        # FLIC
        # Draw face
        draw.circle(img, preds[ref.parts[ds].index('leye')], colors[4], 3 * s)
        draw.circle(img, preds[ref.parts[ds].index('reye')], colors[4], 3 * s)
        draw.circle(img, preds[ref.parts[ds].index('nose')], colors[4], 3 * s)

        # Draw hips
        draw.circle(img, preds[ref.parts[ds].index('lhip')], colors[5], 5 * s)
        draw.circle(img, preds[ref.parts[ds].index('rhip')], colors[7], 5 * s)

    return crop(img, c, s, res)