getANNO.m
1 dataType = '';
2 addpath('dataset/COCO/coco/MatlabAPI'); %此处需要设置工作环境,否则会报错无法找到该路径
-
Matlab设置当前工作环境的方法:双击进入training文件夹即可
19 coco=CocoApi(annFile); % Load COCO annotation file and prepare data structures. 输出初始化的coco object
20 %%
21 my_anno = coco.data.annotations;
-
my_anno data
23 prev_id = -1;
24 p_cnt = 1; %一张图片里的人数
25 cnt = 0; %总的图片数
26 coco_kpt = [];
27
28 for i = 1:1:size(my_anno,2) %size(my_anno, 2)返回my_anno的列数,1返回行数 i: 1~185316(val2014.json)
29
30 curr_id = my_anno(i).image_id; % my_anno的大小等于所有的人数,一张图像可能有多个人,而且image_id是按顺序排列的,例如上图第74张图像中有6个人
31 if(curr_id == prev_id) %判断与上一张图像的image_id是否相同
32 p_cnt = p_cnt + 1; %相同则对curr_id里的person_count + 1
33 else
34 p_cnt = 1; % 新图片,人数从1开始计数
35 cnt = cnt + 1; % 新图片,图片数 + 1
36 end
37 coco_kpt(cnt).image_id = curr_id; %coco_kpt(1).image_id = 74
38 coco_kpt(cnt).annorect(p_cnt).bbox = my_anno(i).bbox; %coco_kpt(1).annorect(1).bbox = my_anno(1).bbox
39 coco_kpt(cnt).annorect(p_cnt).segmentation = my_anno(i).segmentation;
40 coco_kpt(cnt).annorect(p_cnt).area = my_anno(i).area;
41 coco_kpt(cnt).annorect(p_cnt).id = my_anno(i).id;
42 coco_kpt(cnt).annorect(p_cnt).iscrowd = my_anno(i).iscrowd;
43 coco_kpt(cnt).annorect(p_cnt).keypoints = my_anno(i).keypoints;
44 coco_kpt(cnt).annorect(p_cnt).num_keypoints = my_anno(i).num_keypoints;
45 coco_kpt(cnt).annorect(p_cnt).img_width = coco.loadImgs(curr_id).width;
46 coco_kpt(cnt).annorect(p_cnt).img_height = coco.loadImgs(curr_id).height;
47
48 prev_id = curr_id;
49
50 fprintf('%d/%d \n', i, size(my_anno, 2));
51 end
-
修改循环数为50,查看coco_kpt数据