YOLOV4目标检测--计数方法draw_detections_v3

11 篇文章 3 订阅

 YOLOv4检测图片添加置信度和计数

YOLOv4检测图片添加置信度和计数

 

本文章向大家介绍 YOLOv4检测图片添加置信度和计数 ,主要包括 YOLOv4检测图片添加置信度和计数 使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

 

主要修改的image.c文件,在darknet目录下直接ctrl+f搜即可,然后打开,找到draw_detections_v3函数,加入用来计数的变量。(我的改法其实有点问题,如果置信度位数过多的话左上角第二行会重复。我懒的研究,直接把置信度位数改小,让第二行盖过它。)

void draw_detections_v3(.....)
.....
qsort(selected_detections, selected_detections_num, sizeof(*selected_detections), compare_by_probs);
    int image_nut=0;//记录螺母数量 (在image.c的370行左右)
     int image_bolt=0;//记录螺栓数量
    for (i = 0; i < selected_detections_num; ++i) {
            int width = im.h * .002;
            if (width < 1)
                width = 1;
.....
            char nut[30];//*左上角第一行字符串  (430行左右)
             char bolt[30]; //*左上角第二行字符串
            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
            }

....

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 con[20]={0};//置信度添加  450行左右
        sprintf(con, "%.4f", selected_detections[i].det.prob[selected_detections[i].best_class]); 
        strcat(labelstr, ":");
        strcat(labelstr, con);//

        if(!strcmp(names[selected_detections[i].best_class], "nut"))//
        {  
            image_nut++;// 计数开始
            
        }
        else if(!strcmp(names[selected_detections[i].best_class], "bolt"))
        {
            image_bolt++;
            
        }
        //
                image label = get_label_v3(alphabet, labelstr, (im.h*.02));
                //draw_label(im, top + width, left, label, rgb);
                draw_weighted_label(im, top + width, left, label, rgb, 0.7);
....
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);
            }
    if (i==(selected_detections_num-1))//最终结果写入  484行左右
    {        sprintf(nut,"nut_num: %d",image_nut);
            
            sprintf(bolt,"bolt_num: %d",image_bolt);
    }
    
    image label_nut=get_label_v3(alphabet, nut, (im.h*.03));//last varible is size
    draw_label(im, 100, 150, label_nut, rgb); //显示函数
    free_image(label_nut);         
    image label_bolt=get_label_v3(alphabet, bolt, (im.h*.03));//last varible is size
    draw_label(im, 260, 150, label_bolt, rgb);
    free_image(label_bolt);     //
    }
    

    free(selected_detections);
}
  • 0
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值