前言
darknet在检测比较小且比较密集的目标时,会由于框体过粗导致目标难以用肉眼去观察,同时无法在目标框上看出当前目标的置信度值,而当多个目标属于同类时终端中显示的置信度并无法确定对应的时哪个目标。因此,本文介绍简单修改下源代码以解决上述两个问题。
代码修改
进入darknet根目录,打开src目录下image.c文件,在draw_detections_v3函数体内修改(329行)
首先修改369行为.002
// image output
qsort(selected_detections, selected_detections_num, sizeof(*selected_detections), compare_by_probs);
for (i = 0; i < selected_detections_num; ++i) {
int width = im.h * .002; // init .006 change the bbox thin // 369行
if (width < 1)
width = 1;
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[4];
gcvt((selected_detections[i].det.prob[selected_detections[i].best_class] * 100), 4, buff);
char prob[] = ":"; //strat: add coding for show conf in label
strcat(labelstr, prob);
strcat(labelstr, buff);
strcat(labelstr, "%"); // end
image label = get_label_v3(alphabet, labelstr, (im.h*.01)); //init .02 (477行)
在477行image label 上方for循环 } 下方插入上述代码,实现在预测框中显示置信度,同时将477行的.02改成.01
修改完后需要重新编译一下
make clean
make -j8 # 8为cpu核心数
效果
附上darknet-yolov4源码地址:https://github.com/alexeyab/darknet