使用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);
发布了30 篇原创文章 · 获赞 37 · 访问量 4067

猜你喜欢

转载自blog.csdn.net/qq_32188669/article/details/103910694
今日推荐