目标检测数据库 PASCAL 格式的 Ground Truth 的解析函数
最近在做一个目标检测算法,训练时用到了 bootstrap 策略,于是我将PASCAL的 Ground Truth 格式的读取函数从 Matlab 改写为 C++。PASCAL 的标注格式为:
# PASCAL Annotation Version 1.00
Image filename : "对应图片路径"
Image size (X x Y x C) : 宽 x 高 x 3
Database : "数据库名称"
Objects with ground truth : 1 { "PASperson" }
# Note that there might be other objects in the image
# for which ground truth data has not been provided.
# Top left pixel co-ordinates : (0, 0)
# Details for object 1 ("PASperson")
# Center point -- not available in other PASCAL databases -- refers
# to person head center
Original label for object 1 "PASperson" : "UprightPerson"
Center point on object 1 "PASperson" (X, Y) : (257, 187)
Bounding box for object 1 "PASperson" (Xmin, Ymin) - (Xmax, Ymax) : (195, 154) - (297, 468)
我写的函数如下:
#include "stdio.h"
#include "string.h"
#include "stdlib.h" // object bounding rect
struct GtRect {
int x_min; int y_min;
int x_max; int y_max;
}; // ground truth of one image
struct GtRecord {
char* image_name;
GtRect* objs;
int obj_num; int height;
int width; int channels;
}; // return true if c is in char set s
int _is_chars(char c, const char* s, int n)
{
for (int i = ; i != n; ++i) {
if (s[i] == c) {
return ;
}
}
return ;
} void _trim_l(char* inout, const char* s)
{
int len = strlen(inout);
int s_len = strlen(s);
int i = ;
for (;i != len; ++i) {
if (!_is_chars(inout[i], s, s_len)) {
break;
}
}
int d = i;
int new_len = len - d;
for (i = ; i != new_len; ++i) {
inout[i] = inout[i + d];
}
inout[new_len] = '\0';
} void _trim_r(char* inout, const char* s)
{
int len = strlen(inout);
int s_len = strlen(s);
int i = len - ;
for (;i != -; --i) {
if (!_is_chars(inout[i], s, s_len)) {
break;
}
}
inout[i + ] = '\0';
} inline void _trim_lr(char* inout, const char* s)
{
_trim_l(inout, s);
_trim_r(inout, s);
} // read ground truth (pascal format)
//************************************
// Name: gt_pascal_read
// Returns: GtRecord
// const char * path : groundtruth file path
//************************************
GtRecord gt_pascal_read(const char* path)
{
GtRecord ret = {, , , , , };
FILE* f;
fopen_s(&f, path, "r");
int obj_num = ;
int len = ;
GtRect rct;
while (fgets(BUF1, , f) != ) {
int match_type = _match_attr(BUF1);
switch (match_type) {
case :
// read image filename
sscanf_s(BUF1, _GT_ATTR[], BUF2, );
_trim_lr(BUF2, "\n\" ");
len = strlen(BUF2);
ret.image_name = (char*)malloc(len + );
memcpy(ret.image_name, BUF2, len + );
break;
case :
// read image size, channel
sscanf_s(BUF1, _GT_ATTR[], &ret.width, &ret.height,
&ret.channels);
break;
case :
// ignore database name
break;
case :
sscanf_s(BUF1, _GT_ATTR[], &rct.x_min,
&rct.y_min, &rct.x_max, &rct.y_max);
OBJ_BUF[obj_num++] = rct;
break;
case :
// ignore polygon
case :
// ignore pixel map
case :
// ignore label
break;
}
}
fclose(f);
ret.obj_num = obj_num;
if (obj_num > ) {
ret.objs = (GtRect*)malloc(sizeof(GtRect) * obj_num);
memcpy(ret.objs, OBJ_BUF, obj_num * sizeof(GtRect));
}
return ret;
} // release pascal ground truth
//************************************
// Name: gt_pascal_release
// Returns: void
// GtRecord * r
//************************************
void gt_pascal_release(GtRecord* r)
{
free(r->image_name);
free(r->objs);
r->image_name = ;
r->objs = ;
r->width = ;
r->height = ;
r->channels = ;
r->obj_num = ;
}
gt_pascal_read 函数忽略了 groundtruth 文件中的一些属性,例如数据库名称等,如果要加回,可以在函数的几个空的 case 中添加即可。PASCAL 官方提供了几个有用的 Matlab 脚本用于读取和生成这样的 groundtruth 文件,在算法开发的过程中要多利用这样的工具。
目标检测数据库 PASCAL 格式的 Ground Truth 的解析函数的更多相关文章
- 目标检测模型的性能评估--MAP(Mean Average Precision)
目标检测模型中性能评估的几个重要参数有精确度,精确度和召回率.本文中我们将讨论一个常用的度量指标:均值平均精度,即MAP. 在二元分类中,精确度和召回率是一个简单直观的统计量,但是在目标检测中有所不同 ...
- [炼丹术]YOLOv5目标检测学习总结
Yolov5目标检测训练模型学习总结 一.YOLOv5介绍 YOLOv5是一系列在 COCO 数据集上预训练的对象检测架构和模型,代表Ultralytics 对未来视觉 AI 方法的开源研究,结合了在 ...
- 【计算机视觉】目标检测中的指标衡量Recall与Precision
[计算机视觉]目标检测中的指标衡量Recall与Precision 标签(空格分隔): [图像处理] 说明:目标检测性能指标Recall与Precision的理解. Recall与Precision ...
- 目标检测之YOLO V1
前面介绍的R-CNN系的目标检测采用的思路是:首先在图像上提取一系列的候选区域,然后将候选区域输入到网络中修正候选区域的边框以定位目标,对候选区域进行分类以识别.虽然,在Faster R-CNN中利用 ...
- paddlepaddle目标检测之水果检测(yolov3_mobilenet_v1)
一.创建项目 (1)进入到https://aistudio.baidu.com/aistudio/projectoverview/public (2)创建项目 点击添加数据集:找到这两个 然后创建即可 ...
- 深度学习与CV教程(13) | 目标检测 (SSD,YOLO系列)
作者:韩信子@ShowMeAI 教程地址:http://www.showmeai.tech/tutorials/37 本文地址:http://www.showmeai.tech/article-det ...
- zz目标检测
deep learning分类 目标检测-HyperNet-论文笔记 06-06 基础DL模型-Deformable Convolutional Networks-论文笔记 06-05 基础DL模型- ...
- (转) 技术揭秘:海康威视PASCAL VOC2012目标检测权威评测夺冠之道
技术揭秘:海康威视PASCAL VOC2012目标检测权威评测夺冠之道 原创 2016-09-21 钟巧勇 深度学习大讲堂 点击上方“深度学习大讲堂”可订阅哦!深度学习大讲堂是高质量原创内容平台,邀请 ...
- 目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练
将目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练. import xml.etree.ElementTree as ET import numpy as ...
随机推荐
- img控件的居中显示 ---js技术
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- vue的周期函数
beforeCreate(创建前) created(创建后) beforeMount(载入前) mounted(载入后) beforeUpdate(更新前) updated(更新后) beforeDe ...
- luoguP1502过河题解
日常吐(fei)嘈(hua) 这道题作为最近卡了我3天的dp题(最后还是在题解的帮助下冥思苦想才过掉的题),窝觉得此题肥肠之脑洞,写此博客纪念 题解 过河 先来日常手玩样例: 咦感觉怎么手玩答案都像是 ...
- Python之 反射、迭代器、生成器
反射 反射就是通过 内置函数getattr() 以字符串的形式导入模块,以字符串的形式调用模块/对象里方法 l=['add','del','set','find'] for i in l: print ...
- 阶段3 2.Spring_09.JdbcTemplate的基本使用_5 JdbcTemplate在spring的ioc中使用
resources下新建File文件 bean.xml 配置jdbcTemplate 注入DataSource 新建测试方法 复制demo1改个名字叫做demo2 编写Insert的方法
- harbor设置开机自启
[root@bogon harbor]# vi /lib/systemd/system/harbor.service [Unit]Description=RedisAfter=network.targ ...
- Oracle 安装 RAC 11.2.0.4 centos7.4 -udev磁盘绑定/执行root脚本报错
在centos 7.4上安装oracle rac 11.2.0.4 报错及相关解决 $ cat /etc/redhat-release CentOS Linux release 7.4.1708 (C ...
- SpringBoot 和 SpringCloud 之间关系?
SpringBoot:专注于快速方便的开发单个个体微服务(关注微观):SpringCloud:关注全局的微服务协调治理框架,将SpringBoot开发的一个个单体微服务组合并管理起来(关注宏观):Sp ...
- js中dom选择器
document,getElementById("demo"); //通过id查询节点 . document.getElementsByTagName("div&q ...
- 《React+Redux前端开发实战》笔记2:基于Webpack构建的Hello World案例(上)
这次搭建分为两部分:一部分是前期必要配置,一部分是开发React代码. [基于Webpack的React Hello World项目] 1.前期必要配置 (1)首先要确保读者的开发设备上已经安装过No ...