示例#1
0
def run(model, img):
    img_show = img.copy()
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    h, w, c = img.shape
    # 只在最右边或者最下边填充0, 这样不会影响box或者点的坐标值, 所以无需再对box或点的坐标做改变
    if w > h:
        img = cv2.copyMakeBorder(img, 0, w - h, 0, 0, cv2.BORDER_CONSTANT, value=(0, 0, 0))
    else:
        img = cv2.copyMakeBorder(img, 0, 0, 0, h - w, cv2.BORDER_CONSTANT, value=(0, 0, 0))

    img_ori = img.copy()
    img = cv2.resize(img, (netH, netW), interpolation=cv2.INTER_CUBIC)
    img_input = np.expand_dims(img.astype(np.float32) / 255., axis=0)
    factor_x = img_ori.shape[1] / (netW / 4)
    factor_y = img_ori.shape[0] / (netH / 4)

    center_map, kps_reg_map = infer(model, img_input)
    # label = outputs[0]
    spm_decoder = SpmDecoder(factor_x, factor_y, netH // 4, netW // 4)
    joints, centers = spm_decoder([center_map[0], kps_reg_map[0]], score_thres=score, dis_thres=dist)
    print(centers)

    for j, single_person_joints in enumerate(joints):
        cv2.circle(img_show, (int(centers[j][0]), int(centers[j][1])), 8, colors[j % 6], thickness=-1)
        for i in range(14):
            x = int(single_person_joints[2 * i])
            y = int(single_person_joints[2 * i + 1])
            cv2.circle(img_show, (x, y), 4, colors[j % 6], thickness=-1)
            # cv2.putText(img_show, str(i), (x, y), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 250), 1)

    cv2.imshow('result', img_show)
    k = cv2.waitKey(0)
def run(model, img):

    img_show = img.copy()

    h, w, c = img.shape
    # 只在最右边或者最下边填充0, 这样不会影响box或者点的坐标值, 所以无需再对box或点的坐标做改变
    #if w > h:
    #    img = cv2.copyMakeBorder(img, 0, w - h, 0, 0, cv2.BORDER_CONSTANT, value=(0, 0, 0))
    #else:
    #    img = cv2.copyMakeBorder(img, 0, 0, 0, h - w, cv2.BORDER_CONSTANT, value=(0, 0, 0))

    img = img.astype(np.float32) / 255.0
    img = cv2.resize(img, (netH, netW), interpolation=cv2.INTER_CUBIC)
    img_input = np.expand_dims(img, axis=0)
    factor_x = img_show.shape[1] / (netW / 4)
    factor_y = img_show.shape[0] / (netH / 4)

    center_map, kps_reg_map = infer(model, img_input)
    # print (center_map.shape)
    # print (kps_reg_map.shape)
    # label = outputs[0]
    spm_decoder = SpmDecoder(factor_x, factor_y, netH // 4, netW // 4)
    results = spm_decoder([center_map[0].numpy(), kps_reg_map[0].numpy()],
                          score_thres=score,
                          dis_thres=dist)

    for j, result in enumerate(results):
        # print (result)
        center = result['center']
        single_person_joints = result['joints']
        cv2.circle(img_show, (int(center[0]), int(center[1])),
                   5,
                   colors[j % 3],
                   thickness=-1)
        for i in range(12):

            x = int(single_person_joints[2 * i])
            y = int(single_person_joints[2 * i + 1])
            cv2.circle(img_show, (x, y), 4, colors[j % 3], thickness=-1)
            cv2.putText(img, str(i), (x, y), cv2.FONT_HERSHEY_COMPLEX, 1,
                        (0, 0, 250), 1)

    return img_show
示例#3
0
                                     cv2.BORDER_CONSTANT,
                                     value=(0, 0, 0))

        img_ori = img.copy()
        img = cv2.resize(img, (netH, netW), interpolation=cv2.INTER_CUBIC)
        img_input = np.expand_dims(img.astype(np.float32) / 255., axis=0)
        factor_x = img_ori.shape[1] / (netW / 4)
        factor_y = img_ori.shape[0] / (netH / 4)

        # factor_x = 4
        # factor_y = 4
        # img_ori = img

        center_map, kps_reg_map = model(img_input)
        # label = outputs[0]
        spm_decoder = SpmDecoder(factor_x, factor_y, netH // 4, netW // 4)
        joints, centers = spm_decoder([center_map[0], kps_reg_map[0]],
                                      score_thres=score,
                                      dis_thres=dist)
        print(centers)

        for j, single_person_joints in enumerate(joints):
            cv2.circle(img_ori, (int(centers[j][0]), int(centers[j][1])),
                       8,
                       colors[j % 6],
                       thickness=-1)
            for i in range(14):
                x = int(single_person_joints[2 * i])
                y = int(single_person_joints[2 * i + 1])
                cv2.circle(img_ori, (x, y), 4, colors[j % 6], thickness=-1)
                cv2.putText(img_ori, str(i), (x, y), cv2.FONT_HERSHEY_COMPLEX,
示例#4
0
    mode = 'train'
    dataset = get_dataset(mode=mode)

    colors = [[0,0,255],[255,0,0],[0,255,0]]
    for epco in range(1):
        for step, (img, center_map, center_mask, kps_map, kps_map_weight) in enumerate(dataset):
            # print (step)
            # print (img[0].shape)
            # img1 = img[0]
            # label1 = label[0]
            # break
            print ('epoch {} / step {}'.format(epco, step))
            img = (img.numpy()[0] * 255).astype(np.uint8)

            spm_decoder = SpmDecoder(4, 4, params['height']//4, params['width']//4)
            results = spm_decoder([center_map[0].numpy(), kps_map[0].numpy()])

            for j, result in enumerate(results):
                center = result['center']
                single_person_joints = result['joints']
                cv2.circle(img, (int(center[0]), int(center[1])), 5, colors[j%3], thickness=-1)
                for i in range(params['num_joints']):
                    x = int(single_person_joints[2*i])
                    y = int(single_person_joints[2*i+1])
                    cv2.circle(img, (x,y), 4, colors[j%3],thickness=-1)
            cv2.imshow('label', img)
            k = cv2.waitKey(0)
            if k == 113:
                break
示例#5
0
                print(str(imgids[0], encoding='utf-8'))
                break
    else:
        for epco in range(1):
            for step, (img, label) in enumerate(dataset):
                # print (step)
                # print (img[0].shape)
                # img1 = img[0]
                # label1 = label[0]
                # break
                print('epoch {} / step {}'.format(epco, step))
                img = (img.numpy()[0] * 255).astype(np.uint8)

                label = label[0]

                spm_decoder = SpmDecoder(4, 4, center_config['height'] // 4,
                                         center_config['width'] // 4)
                joints, centers = spm_decoder(label)

                for j, single_person_joints in enumerate(joints):
                    cv2.circle(img, (int(centers[j][0]), int(centers[j][1])),
                               8,
                               colors[j % 3],
                               thickness=-1)
                    for i in range(14):
                        x = int(single_person_joints[2 * i])
                        y = int(single_person_joints[2 * i + 1])
                        cv2.circle(img, (x, y), 4, colors[j % 3], thickness=-1)
                        cv2.putText(img, str(i), (x, y),
                                    cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 250),
                                    1)
                cv2.imshow('label', img)