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