YOLO选择出只有某一类的检测框并将框保存在txt中

本文介绍如何使用YOLO仅检测person类别,并将检测框坐标保存到txt文件。通过修改detector.c和image.c文件,以及编写脚本遍历图片,实现了对person的精确预处理,为后续识别步骤提供便利。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

YOLO是用来检测的。小肚就是来将物体检测出,并用物体进行识别,所以YOLO只是一个预处理过程。安装和命令行运行检测在官网上都有,但是唯一的就是,我想要的只有person这一类,并且我想得到框的坐标,从而能crop下来person。因此小肚又要对一窍不通的C/C++进行改编了


—————–踩坑无数,总结了这篇系统的文章,如果喜欢,欢迎大家浏览—————

一、修改examples/detector.c

//about row 640
//void draw_detections(image im, int num, float thresh, box *boxes, float **probs, float **masks, char **names, image **alphabet, int classes);
//模仿draw_detections构造的函数,因此把上面注释掉。不同的是,多加了一个char *filename参数,这是因为想将txt的文件名字保存成图片的名字

void draw_detections_person(char *filename, image im, int num, float thresh, box *boxes, float **probs, float **masks, char **names, image **alphabet, int classes);

draw_detections_person(input, im, l.w*l.h*l.n, thresh, boxes, probs, masks, names, alphabet, l.classes);

二、修改src/image.c

//添加draw_detections_person函数。该函数是在draw_detections的函数基础上修改的
void draw_detections_person(char *filename, image im, int num, float thresh, box *boxes, float **probs, float **masks, char **names, image **alphabet, int classes)
{
    int i;
    //printf("%s.\n", strcat(filename, ".txt"));
    //将filename的文件名提取出来,即去掉.jpg的后缀,加上.txt的后缀
    char *output = filename;
    int haha = 
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值