之前一直没找到c语言的darknet的计数代码,就自己改了。就是一个计数器再显示在识别框上,输出xmin,xmax,ymin,ymax的坐标是因为比赛需要,然而大佬们都不用yolo了根本拼不过。。。很久以前改的可能有的地方做了修
改忘记了,如有问题在评论里问一下。
具体修改就在src文件夹的image.c里,找到draw_detections_v3这个函数修改就行。代码如下,修改部分有中文注释。

void draw_detections_v3(image im, detection* dets, int num, float thresh, char** names, image** alphabet, int classes, int ext_output, char* impath)
{static int frame_id = 0;frame_id++;int selected_detections_num;detection_with_class* selected_detections = get_actual_detections(dets, num, thresh, &selected_detections_num, names);// text outputqsort(selected_detections, selected_detections_num, sizeof(*selected_detections), compare_by_lefts);int i;for (i = 0; i < selected_detections_num; ++i){//计算xmin,xmax,ymin,ymaxfloat xmin = round((selected_detections[i].det.bbox.x - selected_detections[i].det.bbox.w / 2) * im.w);float ymin = round((selected_detections[i].det.bbox.y - selected_detections[i].det.bbox.h / 2) * im.h);float xmax = round((selected_detections[i].det.bbox.x + selected_detections[i].det.bbox.w / 2) * im.w);float ymax = round((selected_detections[i].det.bbox.y + selected_detections[i].det.bbox.h / 2) * im.h);if (xmin < 0){xmin = 0;}if (ymin < 0){ymin = 0;}if (xmax < 0){xmax = 0;}if (ymax < 0){ymax = 0;}const int best_class = selected_detections[i].best_class;printf("%s,%s,%.15f%,", names[best_class], impath, selected_detections[i].det.prob[best_class]);//改输出函数if (ext_output)/* printf("\t(left_x: %4.0f   top_y: %4.0f   width: %4.0f   height: %4.0f)\n",round((selected_detections[i].det.bbox.x - selected_detections[i].det.bbox.w / 2)*im.w),round((selected_detections[i].det.bbox.y - selected_detections[i].det.bbox.h / 2)*im.h),round(selected_detections[i].det.bbox.w*im.w), round(selected_detections[i].det.bbox.h*im.h));printf("\txmin: %4.0f   ymin: %4.0f   xmax: %4.0f   ymax: %4.0f\n",*/printf("%4.0f,%4.0f,%4.0f,%4.0f\n",xmin,ymin,xmax,ymax);elseprintf("\n");int j;for (j = 0; j < classes; ++j) {if (selected_detections[i].det.prob[j] > thresh&& j != best_class) {printf("%s,%s,%.15f%", names[j], impath, selected_detections[i].det.prob[j]);if (ext_output)/* printf("\t(left_x: %4.0f   top_y: %4.0f   width: %4.0f   height: %4.0f)\n",round((selected_detections[i].det.bbox.x - selected_detections[i].det.bbox.w / 2)*im.w),round((selected_detections[i].det.bbox.y - selected_detections[i].det.bbox.h / 2)*im.h),round(selected_detections[i].det.bbox.w*im.w), round(selected_detections[i].det.bbox.h*im.h));*///printf("xmin: %4.0f   ymin: %4.0f   xmax: %4.0f   ymax: %4.0f\n",printf(",%4.0f,%4.0f,%4.0f,%4.0f\n",xmin,ymin,xmax,ymax);elseprintf("\n");}}}// image outputqsort(selected_detections, selected_detections_num, sizeof(*selected_detections), compare_by_probs);//记录识别框IDint imageID_1 = 0;//海胆int imageID_2 = 0;//海参int imageID_3 = 0;//扇贝int imageID_4 = 0;//海星for (i = 0; i < selected_detections_num; ++i){int width = im.h * .006;if (width < 1)width = 1;/*if(0){width = pow(prob, 1./2.)*10+1;alphabet = 0;}*///printf("%d %s: %.0f%%\n", i, names[selected_detections[i].best_class], prob*100);int offset = selected_detections[i].best_class * 123457 % classes;float red = get_color(2, offset, classes);float green = get_color(1, offset, classes);float blue = get_color(0, offset, classes);float rgb[3];//width = prob*20+2;rgb[0] = red;rgb[1] = green;rgb[2] = blue;box b = selected_detections[i].det.bbox;//printf("%f %f %f %f\n", b.x, b.y, b.w, b.h);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;//int b_x_center = (left + right) / 2;//int b_y_center = (top + bot) / 2;//int b_width = right - left;//int b_height = bot - top;//sprintf(labelstr, "%d x %d - w: %d, h: %d", b_x_center, b_y_center, b_width, b_height);// you should create directory: result_img//static int copied_frame_id = -1;//static image copy_img;//if (copied_frame_id != frame_id) {//    copied_frame_id = frame_id;//    if (copy_img.data) free_image(copy_img);//    copy_img = copy_image(im);//}//image cropped_im = crop_image(copy_img, left, top, right - left, bot - top);//static int img_id = 0;//img_id++;//char image_name[1024];//int best_class_id = selected_detections[i].best_class;//sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, best_class_id, names[best_class_id]);//save_image(cropped_im, image_name);//free_image(cropped_im);if (im.c == 1){draw_box_width_bw(im, left, top, right, bot, width, 0.8);    // 1 channel Black-White}else{draw_box_width(im, left, top, right, bot, width, red, green, blue); // 3 channels RGB}if (alphabet){char echinus[7] = "echinus";char holothurian[11] = "holothurian";char scallop[7] = "scallop";char starfish[8] = "starfish";char labelstr[4096] = { 0 };strcat(labelstr, names[selected_detections[i].best_class]);int j;for (j = 0; j < classes; ++j){if (selected_detections[i].det.prob[j] > thresh&& j != selected_detections[i].best_class){strcat(labelstr, ", ");strcat(labelstr, names[j]);}}//添加置信度char buff[10];//_gcvt((selected_detections[i].det.prob[selected_detections[i].best_class] * 100), 5, buff);sprintf(buff, "%.2f", selected_detections[i].det.prob[selected_detections[i].best_class] * 100);char prob[] = ":";strcat(labelstr, prob);strcat(labelstr, buff);strcat(labelstr, "%");char prob2[] = " NO:";strcat(labelstr, prob2);//计数并编号if (!strcmp(names[selected_detections[i].best_class], echinus)){imageID_1++;char buff2[5];strcpy(buff2, "");strcat(labelstr, _itoa(imageID_1, buff2, 10));}else if (!strcmp(names[selected_detections[i].best_class], holothurian)){imageID_2++;char buff2[5];strcpy(buff2, "");strcat(labelstr, _itoa(imageID_2, buff2, 10));}else if (!strcmp(names[selected_detections[i].best_class], scallop)){imageID_3++;char buff2[5];strcpy(buff2, "");strcat(labelstr, _itoa(imageID_3, buff2, 10));}else{imageID_4++;char buff2[5];strcpy(buff2, "");strcat(labelstr, _itoa(imageID_4, buff2, 10));}image label = get_label_v3(alphabet, labelstr, (im.h * .03));draw_label(im, top + width, left, label, rgb);free_image(label);}if (selected_detections[i].det.mask) {image mask = float_to_image(14, 14, 1, selected_detections[i].det.mask);image resized_mask = resize_image(mask, b.w * im.w, b.h * im.h);image tmask = threshold_image(resized_mask, .5);embed_image(tmask, im, left, top);free_image(mask);free_image(resized_mask);free_image(tmask);}}free(selected_detections);
}

附上测试结果(批量测试并保存图片,看了几篇博客,找不到链接了)

输出检测结果(图片、置信度、位置坐标)到txt文档(这个改的地方有点杂,回来整理整理再发出来)

darknetYolov3图片的分类计数、置信度以及输出xmin,xmax,ymin,ymax的结果相关推荐

  1. ArcGIS计算图斑的四邻坐标(XMin,XMax,YMin,YMax)

    1.背景: 在国土,调查等行业业务里面经常有需要计算某个图斑的四邻坐标,即xmax,xmin,ymin,ymax;也就是常说的MBR(最小外包矩形),本教程演示如何计算一个shapefile文件上的图 ...

  2. [转]ArcGIS计算图斑的四邻坐标(XMin,XMax,YMin,YMax)

    1.背景: 在国土,调查等行业业务里面经常有需要计算某个图斑的四邻坐标,即xmax,xmin,ymin,ymax;也就是常说的MBR(最小外包矩形),本教程演示如何计算一个shapefile文件上的图 ...

  3. Pycharm的相关配置:改字体样式和大小、更改图片背景、更改控制台输出的字体颜色

    文章目录 Pycharm的相关配置:改字体样式和大小.更改图片背景.更改控制台输出的字体颜色 一.pycharm更改字体样式和大小 二.pycharm更改图片背景 三.pycharm更改控制台输出的字 ...

  4. php输出图片没有,ThinkPHP里无法输出图片 设置响应头

    今天写了一个PHP生成图片,想用浏览器查看,但是每次打开都是一串乱码,看样子是图片源二进制数据,然后查看了下响应头是text/html,那我明明设置了image/jpeg header("C ...

  5. opencv3--学习笔记(彩色图片直方图均衡化的彩色输出图)

    #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #i ...

  6. Python批量处理表格有用吗_python批量读入图片、处理并批量输出(可用于深度学习训练集的制作)...

    最近工作实在是太忙了,白浪花的项目没有及时跟进,很多知识也没有自学.好了,趁着现在等领导回复微信的时间,我把上周趁着零散时间做的工作总结一下.内容依然小白,但是却很重要. 项目情况简单描述一下,最终要 ...

  7. python图片转换成文字_Python输出汉字字库及将文字转换为图片的方法

    用python输出汉字字库问题1:假设我们知道汉字编码范围是0x4E00到0x9FA5,怎么从十六进制的编码转成人类可读的字呢? 问题2:怎么把unicode编码的字写入文件呢,如果直接用open() ...

  8. matlab打印图片数据,如何用matlab输出高质量(论文级)图片?

    阅读量: 324 用matlab辛辛苦苦计算出来的数据结果,只可惜苦于无法输出一幅高质量的图片,不得不复制粘贴数据到其他绘图软件中绘制.之前在网上搜到一款叫export fig的图像工具箱,可惜效果也 ...

  9. java将图片转化为pdf并输出

    1.导入依赖 <dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox< ...

最新文章

  1. 定义员工类,职工类,管理类
  2. 《系统集成项目管理工程师》必背100个知识点-18项目管理计划的ITTO
  3. SSM中使用Mybatis的PageHelper插件实现分页
  4. poj 1190(剪枝)
  5. 重磅!李飞飞 CS231n 最全学霸笔记精炼版来了
  6. 【JAVASCRIPT】处理剪切板
  7. thinkphp两表联查并且分页
  8. jpa 自定义sql if_常用SQL语句大全总结
  9. 如何对 string 进行Base64编码,解码?
  10. 塔塔建网站服务器,塔塔帝国忘记哪个区怎么办
  11. MySQL 性能监控 4 大指标
  12. Linux系统扩硬盘,Linux系统硬盘扩容
  13. python输出自己的名字_【Python】Python-用大写字母打印你的名字
  14. PHP随机静态页面生成系统源码雨尘SEO系统v1.3
  15. java.lang.UnsatisfiedLinkError: no XXX in java.library.path
  16. iscsi 挂载教程_Windows Server 2008 R2 建立iSCSI存储的教程(图文)
  17. 拓端tecdat|python3用ARIMA模型进行时间序列预测
  18. javascript滚动条响应鼠标滑轮的实现上下滚动事件
  19. ad10搜索快捷键_AD10快捷键解析
  20. Windows技巧:右键文件打开方式,该文件没有与之关联来执行该操作

热门文章

  1. “更新 TKK 失败,请检查网络连接” 解决方法
  2. 招银网络 Java后端面经
  3. 好友克隆自助下单网站_新进合伙人如何发朋友圈
  4. 大神尝试扒迅雷的代码,竟然被扒了个精光!
  5. 商场触摸互动广告机有哪些功能
  6. 使用husky + lint-staged助力团队编码规范
  7. php model module,Yii2用Gii自动生成Module+Model+CRUD
  8. 限制Editext输入字节长度
  9. 编码:隐匿在计算机软硬件背后的语言(2)--二进制
  10. python程序设计,猜数游戏编程实践课程实验