最近在做一个目标检测算法,训练时用到了 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 的解析函数的更多相关文章

  1. 目标检测模型的性能评估--MAP(Mean Average Precision)

    目标检测模型中性能评估的几个重要参数有精确度,精确度和召回率.本文中我们将讨论一个常用的度量指标:均值平均精度,即MAP. 在二元分类中,精确度和召回率是一个简单直观的统计量,但是在目标检测中有所不同 ...

  2. [炼丹术]YOLOv5目标检测学习总结

    Yolov5目标检测训练模型学习总结 一.YOLOv5介绍 YOLOv5是一系列在 COCO 数据集上预训练的对象检测架构和模型,代表Ultralytics 对未来视觉 AI 方法的开源研究,结合了在 ...

  3. 【计算机视觉】目标检测中的指标衡量Recall与Precision

    [计算机视觉]目标检测中的指标衡量Recall与Precision 标签(空格分隔): [图像处理] 说明:目标检测性能指标Recall与Precision的理解. Recall与Precision ...

  4. 目标检测之YOLO V1

    前面介绍的R-CNN系的目标检测采用的思路是:首先在图像上提取一系列的候选区域,然后将候选区域输入到网络中修正候选区域的边框以定位目标,对候选区域进行分类以识别.虽然,在Faster R-CNN中利用 ...

  5. paddlepaddle目标检测之水果检测(yolov3_mobilenet_v1)

    一.创建项目 (1)进入到https://aistudio.baidu.com/aistudio/projectoverview/public (2)创建项目 点击添加数据集:找到这两个 然后创建即可 ...

  6. 深度学习与CV教程(13) | 目标检测 (SSD,YOLO系列)

    作者:韩信子@ShowMeAI 教程地址:http://www.showmeai.tech/tutorials/37 本文地址:http://www.showmeai.tech/article-det ...

  7. zz目标检测

    deep learning分类 目标检测-HyperNet-论文笔记 06-06 基础DL模型-Deformable Convolutional Networks-论文笔记 06-05 基础DL模型- ...

  8. (转) 技术揭秘:海康威视PASCAL VOC2012目标检测权威评测夺冠之道

    技术揭秘:海康威视PASCAL VOC2012目标检测权威评测夺冠之道 原创 2016-09-21 钟巧勇 深度学习大讲堂 点击上方“深度学习大讲堂”可订阅哦!深度学习大讲堂是高质量原创内容平台,邀请 ...

  9. 目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练

    将目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练. import xml.etree.ElementTree as ET import numpy as ...

随机推荐

  1. JavaScript Thread.Sleep()

    What is the JavaScript version of sleep()? Since 2009 when this question was asked, JavaScript has e ...

  2. typescript 类(类的定义、继承、修饰符、抽象类)

    代码: // 本节内容 // 1.类的定义 // 2.类的继承 // 3.访问修饰符 // 4.静态属性和静态方法 // 5.抽象类和多态 // js // function Person(name) ...

  3. ORACLE ASM 日常管理

    ASM概述 Automatic Storage Management(ASM)是Oracle数据库10g中一个非常出色的新特性,它以平台无关的方式提供了文件系统.逻辑卷管理器以及软件RAID等服务.A ...

  4. leetcode-easy-math-326. Power of Three

    mycode class Solution(object): def isPowerOfThree(self, n): """ :type n: int :rtype: ...

  5. 解决Oracle XE报错ORA-12516(oracle回话数超出限制)

    本地安装的oracleXEUniv—oracle特别版,免费用户可以自由使用,但有连接数量和存储限制. 最近遇到一个问题,当我的SSM项目连接本地数据库oracleXE后,我的navicat再连接时就 ...

  6. slub

    1.前言 在Linux中,伙伴系统(buddy system)是以页为单位管理和分配内存.但是现实的需求却以字节为单位,假如我们需要申请20Bytes,总不能分配一页吧!那岂不是严重浪费内存.那么该如 ...

  7. retrofit2+rxjava+okhttp网络请求实现

    第一步:添加依赖: compile 'io.reactivex:rxandroid:1.2.0' compile 'com.squareup.retrofit2:adapter-rxjava:2.1. ...

  8. failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED 错误解决方法

    解决: config = tf.ConfigProto() config.gpu_options.allow_growth = True session = tf.Session(config=con ...

  9. [flask]分页显示列表

    添加分页支持的视图函数 app.py @app.route('/search') def search(): page = request.args.get('page', 1, type=int) ...

  10. CentOS7 通过 YUM 升级 VIM8

    Run 就完了: rpm -Uvh http://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm ...