COCO数据集keypoint部分

article/2025/9/10 8:37:07

COCO数据集总体格式如下:

{"info": {...},"licenses": [...],"images": [...],"annotation": [...],"categories": [...],
}

coco数据集的使用:

from pycocotools.coco import COCO
import matplotlib.pyplot as plt
import cv2
import osannot_path_train = '../datasets/coco_2017_dataset/annotations/person_keypoints_train2017.json'
imgRoot = "D:/PycharmProjects/datasets/coco_2017_dataset"
dataType = "train2017"
coco = COCO(annot_path_train)imgId = coco.getAnnIds(imgIds=552272)
imgInfo = coco.loadAnns(imgId)
print(f'图像{imgId}的信息如下:\n{imgInfo}')imgId = coco.getImgIds(imgIds=552272)
imgInfo = coco.loadImgs(imgId)[0]
print(f'图像{imgId}的信息如下:\n{imgInfo}')imPath = os.path.join(imgRoot, dataType, imgInfo['file_name'])
im = cv2.imread(imPath)
plt.imshow(im);
plt.axis('off')
# plt.show()annIds = coco.getAnnIds(imgIds=imgInfo['id'])  # 获取该图像对应的anns的Id
# print(f'图像{imgInfo["id"]}包含{len(anns)}个ann对象,分别是:\n{annIds}')anns = coco.loadAnns(annIds)
coco.showAnns(anns)
print(f'ann{annIds[2]}对应的mask如下:')
mask = coco.annToMask(anns[2])
plt.imshow(mask); plt.axis('off')
plt.show()

输出为:

图像[538087, 547153, 1206290, 1716667, 1717136, 2165006, 2165777]的信息如下:
[{'segmentation': [[255.14, 151.89, 251.89, 175.68, 244.32, 188.65, 255.14, 202.7, 265.95, 202.7, 277.84, 202.7, 276.76, 237.3, 285.41, 278.38, 307.03, 289.19, 310.27, 247.03, 324.32, 240.54, 352.43, 263.24, 355.68, 312.97, 367.57, 343.24, 400, 367.03, 409.73, 358.38, 402.16, 340, 394.59, 317.3, 390.27, 271.89, 378.38, 241.62, 354.59, 205.95, 335.14, 191.89, 343.78, 178.92, 337.3, 154.05, 314.59, 127.03, 296.22, 129.19, 296.22, 102.16, 283.24, 95.68, 260.54, 104.32, 261.62, 123.78, 261.62, 131.35, 257.3, 147.57, 255.14, 161.62], [286.49, 323.78, 286.49, 337.84, 295.14, 344.32, 312.43, 332.43]], 'num_keypoints': 16, 'area': 16444.5709, 'iscrowd': 0, 'keypoints': [284, 124, 2, 288, 116, 2, 277, 117, 2, 0, 0, 0, 264, 123, 2, 308, 141, 2, 263, 155, 2, 337, 170, 2, 251, 191, 2, 318, 185, 2, 270, 163, 2, 327, 203, 2, 290, 211, 2, 363, 241, 2, 288, 254, 2, 375, 331, 2, 303, 313, 1], 'image_id': 552272, 'bbox': [244.32, 95.68, 165.41, 271.35], 'category_id': 1, 'id': 538087}, {'segmentation': [[632.43, 377.84, 614.05, 400.54, 601.08, 412.43, 577.3, 409.19, 567.57, 394.05, 562.16, 388.65, 539.46, 385.41, 525.41, 376.76, 517.84, 358.38, 535.14, 341.08, 547.03, 331.35, 554.59, 319.46, 554.59, 309.73, 561.08, 295.68, 577.3, 275.14, 583.78, 261.08, 582.7, 258.92, 556.76, 258.92, 538.38, 256.76, 525.41, 243.78, 515.68, 230.81, 516.76, 215.68, 522.16, 213.51, 547.03, 226.49, 560, 227.57, 568.65, 227.57, 580.54, 218.92, 588.11, 211.35, 598.92, 203.78, 603.24, 191.89, 609.73, 177.84, 619.46, 169.19, 623.78, 168.11, 636.76, 168.11, 640, 168.11]], 'num_keypoints': 12, 'area': 18150.97805, 'iscrowd': 0, 'keypoints': [607, 199, 2, 0, 0, 0, 0, 0, 0, 638, 208, 2, 0, 0, 0, 0, 0, 0, 611, 213, 2, 0, 0, 0, 587, 244, 2, 632, 301, 2, 538, 240, 2, 612, 320, 2, 586, 304, 2, 595, 338, 2, 540, 362, 2, 595, 380, 2, 613, 368, 2], 'image_id': 552272, 'bbox': [515.68, 168.11, 124.32, 244.32], 'category_id': 1, 'id': 547153}, {'segmentation': [[245.5, 480, 245.74, 476.17, 244.06, 473.03, 251.3, 454.45, 250.81, 412.45, 250.09, 382.28, 250.09, 364.18, 260.33, 352.86, 259.02, 311.68, 273.97, 306.43, 287.09, 311.94, 305.71, 314.3, 317.51, 317.71, 329.05, 317.97, 329.05, 316.14, 321.97, 311.68, 304.4, 298.83, 317.78, 298.3, 315.94, 294.63, 294.69, 289.91, 282.1, 291.48, 273.71, 292.79, 263.48, 292.27, 255.61, 291.75, 252.47, 280.73, 266.1, 276.53, 274.5, 282.04, 279.22, 274.96, 271.35, 269.19, 250.37, 262.37, 248.79, 240.86, 237.78, 207.81, 231.48, 200.47, 225.97, 191.81, 228.07, 183.16, 237.51, 181.58, 248.01, 180.01, 251.42, 168.47, 251.68, 160.6, 253.25, 157.98, 257.97, 156.4, 254.04, 151.16, 251.42, 144.86, 253.25, 136.73, 252.73, 123.62, 256.14, 119.95, 237.25, 109.45, 213.38, 104.73, 196.6, 106.31, 189.25, 112.6, 181.38, 126.24, 175.35, 150.63, 175.09, 163.75, 178.24, 173.72, 177.98, 189.98, 184.01, 199.22, 179.81, 215.75, 178.24, 233.84, 179.02, 262.17, 179.81, 267.68, 171.42, 309.58, 168.01, 335.28, 167.75, 365.45, 190.04, 376.99, 186.37, 389.32, 185.06, 411.35, 182.96, 431.02, 182.43, 442.82, 180.6, 457.77, 177.19, 467.21, 172.73, 478.43, 172.99, 480]], 'num_keypoints': 10, 'area': 28188.6849, 'iscrowd': 0, 'keypoints': [252, 154, 2, 0, 0, 0, 239, 148, 2, 0, 0, 0, 204, 160, 2, 0, 0, 0, 210, 201, 2, 0, 0, 0, 211, 295, 2, 247, 269, 2, 285, 298, 2, 0, 0, 0, 229, 357, 2, 189, 433, 2, 225, 453, 2, 0, 0, 0, 0, 0, 0], 'image_id': 552272, 'bbox': [167.75, 104.73, 161.3, 375.27], 'category_id': 1, 'id': 1206290}, {'segmentation': [[153.48, 156.52, 174.23, 163.43, 178.18, 172.33, 182.13, 194.06, 184.11, 203.95, 182.13, 243.47, 175.22, 262.25, 176.2, 283, 170.27, 283, 151.5, 286.95, 149.52, 296.83, 137.67, 302.76, 137.67, 296.83, 129.76, 312.64, 128.77, 335.37, 129.76, 350.19, 127.79, 364.02, 128.77, 373.9, 137.67, 386.75, 139.64, 391.69, 140.63, 393.67, 122.84, 403.55, 109.01, 417.38, 103.08, 421.33, 97.15, 418.37, 92.21, 413.43, 91.22, 413.43, 89.25, 407.5, 99.13, 395.64, 109.01, 385.76, 112.96, 382.8, 112.96, 377.86, 110, 363.03, 105.06, 340.31, 107.03, 333.39, 107.03, 317.58, 107.03, 292.88, 111.98, 283.98, 110.99, 275.09, 110, 269.16, 110.99, 266.2, 106.05, 255.33, 104.07, 233.59, 92.21, 222.72, 91.22, 208.89, 87.27, 201.97, 92.21, 182.21, 114.94, 166.4, 107.03, 160.47, 101.11, 146.64, 96.17, 128.85, 96.17, 121.93, 104.07, 113.04, 114.94, 110.07, 128.77, 110.07, 136.68, 115.02, 146.56, 124.9, 149.52, 126.87, 151.5, 132.8, 148.54, 148.61, 148.54, 154.54, 152.49, 159.48]], 'num_keypoints': 14, 'area': 15615.20195, 'iscrowd': 0, 'keypoints': [145, 155, 2, 144, 144, 2, 132, 147, 2, 0, 0, 0, 109, 151, 2, 161, 171, 2, 103, 190, 2, 172, 219, 2, 119, 247, 2, 166, 262, 2, 146, 267, 2, 166, 252, 2, 130, 255, 2, 0, 0, 0, 119, 296, 2, 0, 0, 0, 115, 376, 2], 'image_id': 552272, 'bbox': [87.27, 110.07, 96.84, 311.26], 'category_id': 1, 'id': 1716667}, {'segmentation': [[0, 418.08, 9.18, 425.45, 12.33, 434.58, 25.32, 434.22, 20.41, 427.21, 16.19, 412.47, 22.16, 407.2, 25.32, 406.5, 29.88, 401.94, 20.41, 397.73, 1.81, 383.69]], 'num_keypoints': 0, 'area': 779.02935, 'iscrowd': 0, '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': 552272, 'bbox': [0, 383.69, 29.88, 50.89], 'category_id': 1, 'id': 1717136}, {'segmentation': [[209.45, 98.49, 208.21, 76.05, 214.44, 67.32, 226.91, 61.09, 244.36, 73.56, 241.87, 86.03, 244.36, 97.25, 239.38, 108.47, 211.95, 100.99]], 'num_keypoints': 4, 'area': 1291.0023, 'iscrowd': 0, 'keypoints': [232, 94, 2, 236, 89, 2, 227, 88, 2, 0, 0, 0, 212, 92, 2, 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': 552272, 'bbox': [208.21, 61.09, 36.15, 47.38], 'category_id': 1, 'id': 2165006}, {'segmentation': [[435.61, 363.65, 424.3, 376.85, 436.55, 390.99, 458.24, 378.73, 458.24, 357.99, 459.18, 302.36, 470.5, 290.1, 496.9, 366.48, 499.73, 370.25, 517.64, 357.99, 515.75, 340.08, 500.67, 265.59, 495.38, 249.08, 503.13, 212.25, 500.23, 192.37, 482.29, 175.89, 483.75, 162.32, 487.14, 144.87, 483.26, 130.33, 465.81, 129.85, 452.24, 139.54, 447.88, 149.24, 445.94, 159.41, 454.18, 169.11, 428.49, 170.56, 417.34, 179.29, 409.1, 203.52, 407.65, 208.85, 413.47, 213.7, 398.32, 256.92, 405.49, 288.69, 415.74, 292.78, 422.91, 230.28, 432.13, 272.29, 436.23, 361.44]], 'num_keypoints': 16, 'area': 16305.31245, 'iscrowd': 0, 'keypoints': [474, 166, 2, 478, 158, 2, 467, 157, 2, 0, 0, 0, 448, 158, 2, 495, 193, 2, 427, 179, 2, 480, 246, 2, 417, 225, 2, 463, 288, 2, 411, 266, 2, 471, 247, 2, 440, 242, 2, 493, 293, 2, 445, 285, 2, 501, 349, 2, 441, 362, 2], 'image_id': 552272, 'bbox': [398.32, 129.85, 119.32, 261.14], 'category_id': 1, 'id': 2165777}]
图像[552272]的信息如下:
{'license': 2, 'file_name': '000000552272.jpg', 'coco_url': 'http://images.cocodataset.org/train2017/000000552272.jpg', 'height': 480, 'width': 640, 'date_captured': '2013-11-21 20:53:16', 'flickr_url': 'http://farm3.staticflickr.com/2542/3970944877_5cd66b8655_z.jpg', 'id': 552272}
ann1206290对应的mask如下:

在这里插入图片描述
原图:
在这里插入图片描述

这里输出了一张图片中所有的人物数据,但是突出便是的是我们规定的其中一个。通过更改anns来实现。
介绍一下这段COCO格式数据中所包含的内容,‘segmentation’是标注的区域,翻译过来就是分割,将目标在图像中分割出来,COCO数据集中’segmentation’有两种数据方式:一种是当’iscrowd’: 0的时候,此时表示只有单个对象,使用ploygon(多边形)格式来表示每两个数据表示一个x,y坐标;另一种是当’iscrowd’: 1的时候,这时表示标记了一组对象,此时使用RLE格式,RLE格式是一串只有0和1的数组,0表示不是目标,1表示是目标。之后用类似3051(表示连续三个零和五个一)的格式进行压缩的格式,这组数据中是’iscrowd’: 0的情况。然后’num_keypoints’表示在这张图像中此人身上拥有多少个关节点;'area’表示该区域的面积(area of encoded masks);‘keypoints’表示的是关节点的具体细节,是一个3*k维的数组,k维即是’num_keypoints’,3维表示某点的x,y坐标和标志位v(标识该点是否可见是否被遮挡等信息);'image_id’表示标注的这个人所在的图片;'bbox’表示定位框的信息,len长为4,表示左上角的x,y坐标和框的宽度w和高度h;'category_id’表示所属分类,在这里只有人这一类所以全为1;'id’表示所标注的人的ID,因为一张图片中可以有很多,所以一段标注信息’image_id’可以是重复的但是’id’是唯一的。
所以上图输出的是为图像id为191280的图像,标注的图对应的id为1206290。


http://chatgpt.dhexx.cn/article/6tJusa3N.shtml

相关文章

Rethinking Keypoint Representations: Modeling Keypoints and Poses as Objects for Multi-Person Human

该论文发表于ECCV2022 题目:重新思考关键点表征方法:将关键点和人体姿态作为目标建模以进行多人姿态估计 Abstract In keypoint estimation tasks such as human pose estimation,heatmap-based regression is the dominant approach despite possess…

[1] A Keypoint-based Global Association Network for Lane Detection

A Keypoint-based Global Association Network for Lane Detection 0. 摘要 概括车道线检测方法: (1)基于Anchor定位的方法,自顶向下根据路线图把预设定的Anchor回归到车道线上。缺点是对复杂车道线不够灵活; &#…

cv::KeyPoint中response的介绍

1. Opencv中的KeyPoint类介绍 KeyPoint类的构造函数如下: KeyPoint(); KeyPoint(Point2f _pt, float _size, float _angle-1, float _response0, int _octave0, int _class_id-1); KeyPoint(float x, float y, float _size, float _angle-1, float _response0, int _octave0…

11种Anchor-free目标检测综述 -- Keypoint-based篇

点击上方“3D视觉工坊”,选择“星标” 干货第一时间送达 导读 anchor-free目标检测算法分为两种,一种是DenseBox为代表的Dense Prediction类型,另一种则是以CornerNet为代表的Keypoint-bsaed Detection类型,以检测目标关键点为主…

SMOKE: Single-Stage Monocular 3D Object Detection via Keypoint Estimation

动机: in this paper that predicts a 3D bounding box for each detected object by combining a single keypoint estimate with regressed 3D variables. As a second contribution, we propose a multi-step disentangling approach for constructing the 3D b…

《PCL Docs 案例详解》KeyPoint——SIFT 关键点提取

SIFT 关键点提取 本节演示如何检测点云的SIFT 关键点。SIFT 即尺度不变特征变换(Scale-invariant feature transform,SIFT) ,最初用于图像处理领域的一种描述。这种描述具有尺度不变性,可以在图像中检测出关键点,是一种局部特征描述。 完整…

OpenCV中KeyPoint类

https://blog.csdn.net/u010821666/article/details/52883580 Opencv中KeyPoint类中的默认构造函数如下: CV_WRAP KeyPoint() : pt(0,0), size(0), angle(-1), response(0), octave(0), class_id(-1) {} 现分析各项属性 pt(x,y):关键点的点坐标; si…

Anchor-free目标检测综述 -- Keypoint-based篇

早期目标检测研究以anchor-based为主,设定初始anchor,预测anchor的修正值,分为two-stage目标检测与one-stage目标检测,分别以Faster R-CNN和SSD作为代表。后来,有研究者觉得初始anchor的设定对准确率的影响很大&#x…

Opencv中特征点Keypoint的解读(特征点与坐标的相互转换)

Opencv中特征点Keypoint的解读 特征点的生成特征点到坐标的转换坐标到特征点的转换 在我们学习特征点检测时,使用特征点检测器,比如ORB和SIFT生成特征点(FAST和SURF好像已经申请专利,较新版本可能用不了),通常生成的特征点形式是一…

COCO数据集Keypoint标注格式梳理和使用COCO-Annotator在自有数据集上进行标注

这里写自定义目录标题 COCO数据集Keypoint标注格式COCO数据集官网Keypoint Detection关键点检测统一数据格式Keypoint标注 使用COCO-Annotator标注自有数据集在Ubuntu 18.04上安装COCO-Annotator安装Docker和Docker-Compose安装COCO Annotator启动COCO Annotator使用COCO Annot…

OpenCV学习之KeyPoint

OpenCV中CV_EXPORTS类别KeyPoint与KeyPointsFilter头文件分析 用OpenCV一段时间了,说实话KeyPoint接触也算比较多,一直没有时间对其数据结构进行分析。今天打开源码对其keypoint.cpp文件进行简单分析一下:keypoint.cpp主要包含两个类KeyPoint…

ubuntu引导删除+win10引导修复

Windowsubuntu双系统,删除安装linux磁盘后没有删除其引导,删其引导的步骤为 使用快捷键winx,打开Windows PowerShell(管理员)(A),依次输入如下命令: 打开diskpart diskpart 列出系统中所有的磁盘 list disk 选择…

win10+ubuntu18.04 双系统修复ubuntu启动引导

win10ubuntu18.04 双系统修复ubuntu启动引导 因为windows是不能引导linux的,而每次win10升级或恢复都会将linux的启动引导覆盖掉,导致无法进入linux, 所以一直就禁止了win10更新.这几天win10出了点小毛病,所以就狠下心来恢复了系…

ubuntu 双系统启动引导修复

1、 准备一个安装U盘,插入电脑开机>选择U盘启动>选择试用Try ubuntu without install。 2、 进入系统后,用CtrlAltT快捷键打开终端,获取root权限,执行以下命令: sodu passwd sudo apt-get install s…

win10+ubuntu双系统,重装win10后修复ubuntu引导的方法

笔记本型号:联想拯救者Y7000P 2019版 操作系统:Windows 10Ubuntu 18.04 LTS 问题:重装系统后发现没办法进入到Ubuntu 解决办法: 首先,我们需要准备一个Ubuntu安装U盘,也就是我们之前进行Ubuntu系统安装…

Windows\Ubuntu修复UEFI引导

目录 1、修复Windows引导2、修复Ubuntu的引导 1、修复Windows引导 修复Windows的EFI引导需要使用到的工具为大白菜装机工具,官网是http://www.winbaicai.com/。使用大白菜制作好装机工具以后,重启选择U盘启动(一定要选“UEFI:你的…

Ubuntu boot-repair系统修复引导

Ubuntu系统修复引导 笔记本上本来已经有了一个ubuntu和一个windows,但是那天作死,想要在移动固态硬盘上安装一个ubuntu,方便使用,结果装完了之后必须要将移动固态插在笔记本上,才能够正常引导。 上网查了半天&#xf…

ubuntu修复启动引导

1. 解决步骤: 1:准备一个安装U盘,插入电脑->开机->选择试用Try ubuntu without install 2:打开终端(Open Terminal),获取root权限…

双系统Ubuntu 引导修复(Boot Repair)

安装完双系统,如果在使用过程中不小心删除了Ubuntu引导向,则会导致开机后无法选择进入Ubuntu系统。或者当我们重装了windows系统后,也会发现原来的Ubuntu引导不见了,当出现这两种情况之一时,最好的解决办法不是重新把U…

Win10+Ubuntu双系统修复Ubuntu系统引导

这两天笔者安装win10ubuntu16.04双系统,因为网络上能找到大量的资料,安装过程此处就不多讲。因为笔者电脑是华硕主板,bios默认设置为安全启动,笔者猜测会阻止加载ubuntu引导,导致双系统不能随意引导。先不管那么多&…