修改代码,使得 yolov3输出选中框的坐标信息

2023-05-16

1 修改darknet\image.c中的draw_detections_v3函数

主要修改三段代码:
第一段:
在这里插入图片描述
第二段:
在这里插入图片描述
第三段:
在这里插入图片描述
修改完的draw_detections_v3函数如下:

void draw_detections_v3(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output)
{
    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);

    //创建保存位置信息txt文档
    FILE *fp;
    if ((fp = fopen("BoxValue.txt", "w+")) == NULL) {
        printf("创建文档失败:\n");
    }

    // text output
    qsort(selected_detections, selected_detections_num, sizeof(*selected_detections), compare_by_lefts);
    int i;
    for (i = 0; i < selected_detections_num; ++i) {
        const int best_class = selected_detections[i].best_class;
        printf("%s: %.0f%%", names[best_class],    selected_detections[i].det.prob[best_class] * 100);
        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));
        else
            printf("\n");
        int j;
        for (j = 0; j < classes; ++j) {
            if (selected_detections[i].det.prob[j] > thresh && j != best_class) {
                printf("%s: %.0f%%\n", names[j], selected_detections[i].det.prob[j] * 100);
            }
        }
    }

    // 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 * .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

                //输出坐标信息到文本文件
                fprintf(fp, "左部边框的位置:%d 顶部边框的位置:%d 右部边框的位置:%d 底部边框的位置:%d\n", left, top, right, bot);

            }
            if (alphabet) {
                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]);
                    }
                }
                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);

    //关闭坐标文本文件
    fclose(fp);
}

2 重新编译生成项目

生成新的darknet.exe后,再次运行测试过程,会在darknet.exe所在的目录产生一个BoxValue.txt文件。

3 输出结果

在这里插入图片描述
左图第一行是右图从上到下第一个框的坐标信息;第二行是第二个的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

修改代码,使得 yolov3输出选中框的坐标信息 的相关文章

  • YOLOv3 从入门到部署:(五)YOLOv3模型的部署(基于C++ opencv)

    文章目录 YOLOv3 从入门到部署 xff1a xff08 五 xff09 YOLOv3模型的部署 xff08 基于C 43 43 opencv xff09 目录关于opencv的DNN介绍代码讲解效果展示 YOLOv3 从入门到部署 x
  • Win10上yolov3的配置及使用教程(VS2019)

    yolo论文翻译 或https zhuanlan zhihu com p 35023499 yolo官网 目录 硬件环境 安装教程 安装CUDA和cuDNN 下载darknet 修改darknet vcxproj 修改darknet sln
  • 【YOLOv3 decode】YOLOv3中解码理解decode_box

    文章目录 1 解码是什么意思2 代码解读3 生成网格中心 代码详解4 按照网格格式生成先验框的宽高 代码详解5 感谢链接 1 解码是什么意思 在利用YOLOv3网络结构提取到out0 out1 out2之后 xff0c 不同尺度下每个网格点
  • 多GPU训练keras-yolov3

    qqwweee keras yolo3提供的版本代码没有多GPU选项 xff0c 因为网络的输出是一个loss xff0c 使用keras提供的multi gpu model函数时会报错 xff0c 因为multi gpu model的原理
  • YOLOv3

    YOLOv3 论文信息论文标题 xff1a 论文作者 xff1a 收录期刊 会议及年份 xff1a 论文学习YOLOv3 网络架构 xff1a YOLO 输出特征图解码 xff08 前向过程 xff09 xff1a 训练策略与损失函数 xf
  • yolov3详解

    目录 1 anchor的计算机制 2 anchor对应机制 3 网络结构 4 训练过程 5 测试过程 1 anchor的计算机制 锚框anchor是真值框和预测框之间的桥梁 xff1a 预测框在锚框基础上 xff0c 预测出框的大小 xff
  • 使用Keras版本的Yolov3训练自己的数据集和进行目标检测时,需要注意的一些问题

    最近因为工作需要 xff0c 使用了Yolo v3做目标检测 由于它自带的数据集完全不能够满足需要 xff0c 只能从头开始自己训练 当然这必须要用python来做了 xff0c 不能用C语言 首先 xff0c 我发现那个著名的Keras版
  • ubuntu18中yolov3检测图片显示进程已杀死

    病因 xff1a 设备带不动YOLO的进程 解决方法 xff1a 此前本人ubuntu的内存设置为2g xff0c 将内存改为4g后再次检测凸显显示检测成功
  • yolov3、yolov5和DETR在NVIDIA Xavier测速(TensorRT)

    本人实测YoloV3 YoloV5和DETR的TensorRT版本在NVIDIA Xavier上的测速结果如下 xff0c 任何问题留言讨论
  • yoloV3 darknet GPU手把手从编译到训练再到C++调用API

    我要先声明一下 xff0c 系统是Ubuntu18 04 xff0c 我的机器已经装好了opencv4 1 1 和 cuda10 0 的 xff0c 过程可参考我另一篇博客 xff0c 这部分不再说明 IDE使用qtcreator 1 下载
  • c++ 调用yolov3-yolov4

    ifdef WIN32 define OPENCV define GPU endif include lt iostream gt include lt windows h gt include 34 yolo v2 class hpp 3
  • 极简版pytorch实现yolov3-tiny

    参考https github com bubbliiiing yolo3 pytorchtrain py流程 xff1a 加载数据dataloader py正向传播tiny py反向传播loss pydataloader py span c
  • 【YOLOv3 decode】YOLOv3中解码理解decode_box

    文章目录 1 解码是什么意思2 代码解读3 生成网格中心 代码详解4 按照网格格式生成先验框的宽高 代码详解5 感谢链接 1 解码是什么意思 在利用YOLOv3网络结构提取到out0 out1 out2之后 xff0c 不同尺度下每个网格点
  • C++调用Yolov3模型实现目标检测

    C 43 43 调用Yolov3模型实现目标检测 使用开源权重文件 xff0c 此训练模型包含80种物体 文件下载地址 xff1a 预训练权重文件 xff1a https pjreddie com media files yolov3 we
  • 基于KITTI数据集的KERAS-YOLOV3实践

    数据整理 KERAS YOLOV3的GITHUB地址 xff1a https github com yangchengtest keras yolo3 该项目支持的数据结构 xff1a One row for one image Row f
  • Yolov3+C+++opencv+VS2015成功检测

    nbsp 前言 nbsp nbsp nbsp 最近在用yolov3进行目标检测 也有一个多星期了 想把最近做出的一些成果记录下来 供大家参考下 我的运行环境是C opencv VS2015 yolov3 下面将简单介绍下yolo的一些思想
  • YOLO v3基于ROS应用记录

    有时候 就要敢于背上超出自己预料的包袱 真的努力后 你会发现自己要比想象的优秀很多 愿在别人眼里算不上梦想的梦想 成真 言归正传 记录下之前在ROS下跑yolov3的历程吧 感觉现在视觉感知领域用yolo的比faster RCNN多很多了
  • YOLOv3计算模型的mAP

    一 先测试一下大神的数据 在这里下载 https github com Cartucho mAP 1 解压之后如下图所示 input文件夹里面放的是测试集的ground truth 模型的测试结果 和测试集 scripts文件夹里面放的是一
  • 深入浅出Yolo系列之Yolov3&Yolov4&Yolov5&Yolox核心基础知识完整讲解

    因为工作原因 项目中经常遇到目标检测的任务 因此对目标检测算法会经常使用和关注 比如Yolov3 Yolov4算法 Yolov5算法 Yolox算法 当然 实际项目中很多的第一步 也都是先进行目标检测任务 比如人脸识别 多目标追踪 REID
  • 深度学习初探——yolov3经典目标检测算法

    提示 文章写完后 目录可以自动生成 如何生成可参考右边的帮助文档 目录 前言 一 yolov3的网络结构 二 利用Darknet 53进行特征提取 1 残差网络 2 代码实现 三 利用FPN特征金字塔进行特征增强和预测输出 1 利用FPN特

随机推荐