examples/darknet.c文件中若使用detect命令可以看到调用了test_detector.

...
else if (0 == strcmp(argv[1], "detect")){
float thresh = find_float_arg(argc, argv, "-thresh", .24);
char *filename = (argc > 4) ? argv[4]: 0;
char *outfile = find_char_arg(argc, argv, "-out", 0);
int fullscreen = find_arg(argc, argv, "-fullscreen");
test_detector("cfg/coco.data", argv[2], argv[3], filename, thresh, .5, outfile, fullscreen);
}
...

test_detector位于examples/detector.c :562,对其识别结果调用了draw_detections,在入口

void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes)

中,存储了识别结果的是dets,识别数量为num.

dets结构为:

typedef struct detection{
box bbox;
int classes;
float *prob;
float *mask;
float objectness;
int sort_class;
} detection;

box 结构为:

typedef struct{
float x, y, w, h;
} box;

那是不是直接使用如下的访问方式就行了呢?

printf("x=%lf,y=%lf,w=%lf,h=%lf",
dets->bbox.x,dets->bbox.y,
dets->bbox.w,dets->bbox.h);

但是运行结果并不如意

x=0.324301,y=0.611036,w=0.313848,h=0.573097

其实获取正确的矩形数据应该在draw_detections里寻找才是,果不其然,bingo!

void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes)
{
...
for(i = 0; i < num; ++i){
... int left = (b.x-b.w/2.)*im.w;
int right = (b.x+b.w/2.)*im.w;
int top = (b.y-b.h/2.)*im.h;
int bot = (b.y+b.h/2.)*im.h; if(left < 0) left = 0;
if(right > im.w-1) right = im.w-1;
if(top < 0) top = 0;
if(bot > im.h-1) bot = im.h-1; // add
printf("left=%d,right=%d,top=%d,bot=%d\n",left,right,top,bot);
// end add
...
}

将其在test_detector中嵌入,运行效果如下:

left=128,right=369,top=186,bot=517
left=533,right=621,top=94,bot=157
left=465,right=679,top=71,bot=169
left=205,right=576,top=151,bot=449 ___________________________ (left,top)-----------
| |
| |
---------------(right,bot)

>[1] box,detection的定义在include\darknet.h
>[2] detector.c在examples\detector.c
>[3] image.c在src\image.c

最新文章

  1. 表格里使用text-overflow后不能隐藏超出的文本的解决方法
  2. 开源文档管理工具Joomla的网站安装
  3. EntityFramework left join
  4. APICloud全面支持WiFi真机同步和实时预览功能
  5. 开源项目:windows下使用MinGW+msys编译ffmpeg
  6. C++之vector用法
  7. 广播接收者 BroadcastReceiver 示例-2
  8. QT下资源使用和资源占用…(可以动态加载资源文件,这样不占内存)
  9. 怎样调通微信支付及微信发货通知接口(Js API)
  10. HDU 2829 Lawrence(动态规划-四边形不等式)
  11. oracle安装时,条件检查不通过解决办法
  12. 对java多态的理解
  13. oracle针对某列让特定信息排序[decode]
  14. 创建一个dynamics 365 CRM online plugin (三) - PostOperation
  15. UIScrollView _getDelegateZoomView bug 经历
  16. sqlite3调试
  17. SWF运行时判断两个DisplayObject是否同个类型,属于flash professional库中的同一个元件
  18. MAC下常用命令的中文帮助文档(man) 出现错误
  19. Minimum Sum of Array(map迭代器)
  20. Python 函数 -globals()

热门文章

  1. iOS之创建通知、发送通知和移除通知的坑
  2. 使用js函数格式化xml字符串带缩进
  3. js 获取任意一个元素的任意一个样式属性的值
  4. 【rabbitmq消息队列配置】
  5. 一、Vue项目构建
  6. Quote Helper
  7. hadoop生态搭建(3节点)-11.storm配置
  8. 分布式时间同步ntp安装
  9. Spark RDD API详解之:Map和Reduce
  10. 报错: Name node is in safe mode