人体骨骼关键点检测

人体骨骼关键点检测

  1. coco数据集获取
    从官网上下载coco数据集:会有一个这个的文件:person_keypoints_val2017.json,coco数据集提供了python的API .
    由于coco数据集可以用于需要的任务,如:语义分割、人体分割、物体分类等,应用时需要选择正确的josn文件。

    1.1 josn 文件示例(删减版)
    josn文件分为:几个节点 “info”: 、“licenses”: 、“images”:、“annotations”: 、 “categories”: ;
    每个节点中包含了许多的子节点,子节点中友有许多的属性;

{
    "info": 
    {
        "description": "COCO 2017 Dataset",
        "url": "http://cocodataset.org",
        "version": "1.0","year": 2017,
        "contributor": "COCO Consortium",
        "date_created": "2017/09/01"},
    "licenses": 
    [
        {"url": "http://creativecommons.org/licenses/by-sa/2.0/","id": 5,"name": "Attribution-ShareAlike License"},
        {"url": "http://creativecommons.org/licenses/by-nd/2.0/","id": 6,"name": "Attribution-NoDerivs License"},
        {"url": "http://flickr.com/commons/usage/","id": 7,"name": "No known copyright restrictions"},
        {"url": "http://www.usa.gov/copyright.shtml","id": 8,"name": "United States Government Work"}
        


    ],

    "images": ###注意这里!!!  (节点)
    [
        {   "license": 4, #属性
            "file_name": "000000425226.jpg", ###注意这里!!!
            "coco_url": "http://images.cocodataset.org/val2017/000000397133.jpg",
            "height": 427,
            "width": 640,
            "date_captured": "2013-11-14 17:02:52",
            "flickr_url": "http://farm7.staticflickr.com/6116/6255196340_da26cf2c9e_z.jpg",
            "id": 397133  ###注意这里!!!
        }, #子节点
        {   "license": 1,
            "file_name": "000000440475.jpg", ###注意这里!!!
            "coco_url": "http://images.cocodataset.org/val2017/000000037777.jpg",
            "height": 230,
            "width": 352,
            "date_captured": "2013-11-14 20:55:31",
            "flickr_url": "http://farm9.staticflickr.com/8429/7839199426_f6d48aa585_z.jpg",
            "id": 37777 ###注意这里!!!
        }
    ],
    "annotations": 
    [
        {
            "segmentation": 
                [[125.12,539.69,140.94,522.43,100.67,496.54,84.85,469.21,73.35,450.52,104.99,342.65,168.27,290.88,179.78,288,189.84,286.56,191.28,260.67,202.79,240.54,221.48,237.66,248.81,243.42,257.44,256.36,253.12,262.11,253.12,275.06,299.15,233.35,329.35,207.46,355.24,206.02,363.87,206.02,365.3,210.34,373.93,221.84,363.87,226.16,363.87,237.66,350.92,237.66,332.22,234.79,314.97,249.17,271.82,313.89,253.12,326.83,227.24,352.72,214.29,357.03,212.85,372.85,208.54,395.87,228.67,414.56,245.93,421.75,266.07,424.63,276.13,437.57,266.07,450.52,284.76,464.9,286.2,479.28,291.96,489.35,310.65,512.36,284.76,549.75,244.49,522.43,215.73,546.88,199.91,558.38,204.22,565.57,189.84,568.45,184.09,575.64,172.58,578.52,145.26,567.01,117.93,551.19,133.75,532.49]],
            "num_keypoints": 10,
            "area": 47803.27955,
            "iscrowd": 0,
            "keypoints": 
                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,142,309,1,177,320,2,191,398,2,237,317,2,233,426,2,306,233,2,92,452,2,123,468,2,0,0,0,251,469,2,0,0,0,162,551,2],
            "image_id": 425226,
            "bbox": [73.35,206.02,300.58,372.5],
            "category_id": 1,###注意这里!!!
            "id": 183126  ###注意这里!!!
        },
        {
            "segmentation": 
                [[492.38,238.33,491.91,234.15,494.47,227.65,495.17,215.1,497.02,199.54,503.53,197.22,503.3,194.43,503.3,190.95,506.08,183.51,511.89,185.84,514.21,187,514.21,196.29,521.88,200.7,526.76,216.03,520.25,227.65,519.56,234.38,519.09,239.49,519.09,244.84,519.56,246.93,518.16,248.32,516.3,256.91,510.03,256.45,513.28,240.89]],
            "num_keypoints": 13,
            "area": 1394.7431,
            "iscrowd": 0,
            "keypoints":
                [508,192,2,510,191,2,506,191,2,512,192,2,503,192,1,515,202,2,499,202,2,524,214,2,497,215,2,516,226,2,496,224,2,511,232,2,497,230,2,0,0,0,0,0,0,0,0,0,0,0,0],
            "image_id": 440475,
            "bbox": [491.91,183.51,34.85,73.4],
            "category_id": 1, ###注意这里!!!
            "id": 183302  ###注意这里!!!
        },
        {
            "segmentation": 
            {"counts": [8214,6,629,17,2,6,614,28,611,29,610,31,609,31,609,32,608,32,608,32,608,31,609,31,610,29,612,27,615,16,3,4,620,11,35186,6,633,9,630,11,628,14,626,14,626,15,625,15,625,16,624,16,624,16,625,14,627,13,628,11,631,8,634,4,40318,5,629,14,624,17,622,19,620,20,619,22,617,23,617,23,617,22,618,22,618,21,619,7,1,4,3,4,621,6,3,1,631,3,638,1,133135,5,633,8,631,10,630,10,630,11,629,11,629,11,629,11,629,11,629,11,629,10,631,9,632,7,634,4,99294],"size": [640,549]},
            "num_keypoints": 0,
            "area": 962,
            "iscrowd": 1,
            "keypoints": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
            "image_id": 374545,
            "bbox": [12,524,381,33],
            "category_id": 1, ###注意这里!!!
            "id": 900100374545 ###注意这里!!!
        }
    ],
    "categories": ###注意这里!!!
    [
        {
            "supercategory": "person",
            "id": 1,
            "name": "person",
            "keypoints": 
                ["nose","left_eye","right_eye","left_ear","right_ear","left_shoulder","right_shoulder","left_elbow","right_elbow","left_wrist","right_wrist","left_hip","right_hip","left_knee","right_knee","left_ankle","right_ankle"],
            "skeleton":
                [[16,14],[14,12],[17,15],[15,13],[12,13],[6,12],[7,13],[6,7],[6,8],[7,9],[8,10],[9,11],[2,3],[1,2],[1,3],[2,4],[3,5],[4,6],[5,7]]
        }
    ]
}

1.2 coco python API 解读

from pycocotools.coco import COCO
import numpy as np
import skimage.io as io
import matplotlib.pyplot as plt
import pylab
import cv2 


annFile='F:/cocodata/my_test_read_cocodata/person_keypoints_val2017.json'

# initialize COCO api for instance annotations
coco=COCO(annFile)  #初始化coco对象


temp = coco.getCatIds() #获取“categories”中所有子节点的id,返回id列表

# display COCO categories and supercategories
cats = coco.loadCats(temp)  #获取“categories”中的节点

nms=[cat['name'] for cat in cats] # categories节点的子节点中的“name” 属性
print('COCO categories: \n{}\n'.format(' '.join(nms)))

nms = set([cat['supercategory'] for cat in cats]) # categories子节点的“supercategory” 属性
print('COCO supercategories: \n{}'.format(' '.join(nms)))


# get all images containing given categories, select one at random
catIds = coco.getCatIds(catNms=['person','dog','skateboard']) #由 类别名称 获取类别id
imgIds = coco.getImgIds(catIds=catIds ) #根据类别id 获取这一类的图像id(图像编号)
imgIds = coco.getImgIds(imgIds = imgIds) #根据图像编号(id) 获取图像的id(编号)

for i in range(len(imgIds)):

    img = coco.loadImgs(imgIds[i])[0]  #根据图像编号(id) 在image节点下寻找子节点

    # load and display image
    # I = io.imread('%s/images/%s/%s'%(dataDir,dataType,img['file_name']))
    # use url to load image
    print("F:\\cocodata\\val2017\\"+img['file_name']) #获取image子节点的“file_name”属性

    I = io.imread("F:\\cocodata\\val2017\\"+img['file_name'])

    # load and display instance annotations
    plt.imshow(I); plt.axis('off')
    
    annIds = coco.getAnnIds(imgIds=img['id'], catIds=catIds, iscrowd=None) #根据image子节点中的id 、类别id 寻找对应的 “annotations”中的id
    anns = coco.loadAnns(annIds) #根据“annotations”子节点中的id 寻找对应此id对应的zi节点
    coco.showAnns(anns) #将“annotations”子节点中的segmentation属性和keypoints属性加载到图像上;

    plt.savefig('./relust/temp%d.png'%i)   #存储图片,可选
    plt.close("all")
    image_temp = cv2.imread("./relust/temp%d.png"%i)
    cv2.imshow("test",image_temp)
    cv2.waitKey(10)
#由于plt Agg 问题在vscode中显示不出来,用python-opencv 过度了一下。凑活看吧!

总结:
应用上边的程序可以看出来人体骨骼关键点标注的情况;但是标注数据不是很理想。
接下了就需要搭建训练网络和两个map(相当与label)的生成了.

你可能感兴趣的:(Deep,learning)