使用darknet中c语言函数对图片进行目标检测

使用darknet中c语言函数对图片进行目标检测

代码如下:

#include  "/home/.../darknet/include/darknet.h"
static network *net;
static layer l;
image **alphabet;
char **names;
char cfgfile[100] = ".../yolov2-tiny-voc.cfg";	//加载配置文件
char weightfile[100] = ".../yolov2-tiny-voc.weights";	//加载权重
char name_list[100] = ".../voc.names";	//加载名称标签
net = load_network(cfgfile, weightfile, 0);	//加载网络
set_batch_network(net, 1);
names = get_labels(name_list);
network_predict_image(net, image_buffer);	//处理图片image_buffer
detection *dets = get_network_boxes(net, image_buffer.w, image_buffer.h, thresh, hier, 0, 1, &nboxes);		//获取检测结果
if(nms > 0) 
	do_nms_obj(dets, nboxes, classes, nms);
for(int i = 0; i < nboxes; ++i)		//nboxes图片检测出的目标数
{
	for(int j = 0; j < classes; ++j)	//classes目标种类
    {
         if(dets[i].prob[j] > thresh)	//thresh自定义阈值
          {
                g_print("@ j = %d(names), %.0f%% \n", j ,dets[i].prob[j]*100);
			    draw_detections(image_buffer, dets, nboxes, thresh, names, alphabet, classes);	//对图像上的目标进行标注
			    dets[i].prob[j] = 0;
          }
     }       
}
free(image_buffer.data);
free_detections(dets, nboxes);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值