win10修改darknet(yolov3)源代码令其裁剪出bbox并保存到本地

本文介绍了如何在Windows上的Darknet(YOLOv3)源代码中修改`image.c`,以实现在检测单张图片和视频时,裁剪出边界框(Bounding Box)并保存到本地,同时不显示边界框。主要涉及修改`image.c`中的函数以转换图片格式适应OpenCV输出,并调整代码以实现视频实时裁剪。
摘要由CSDN通过智能技术生成

0.参考链接


适用windows的darknet源代码:https://github.com/AlexeyAB/darknet
windows环境下编译方法:https://blog.csdn.net/StrongerL/article/details/81007766
darknet在windows下的源代码和Linux下的不太一样,要修改的地方也有所不同。

1.修改image.c中draw_detections_v3函数


这个修改后的效果是,检测单张图片时对每个人的类别裁剪出来保存到本地,并且不再有bbox展现出来

首先添加一个函数

IplImage* image_to_iplImage(image p,IplImage* disp){
   
	// 将image结构体中存放的一维数组转换成二维图像
		image copy = copy_image(p);
		if(p.c == 3) rgbgr_image(copy);
		int x,y,k;
		disp = cvCreateImage(cvSize(p.w,p.h), IPL_DEPTH_8U, p.c);
		int step = disp->widthStep;
		for(y = 0; y < p.h; ++y){
   
			for(x = 0; x < p.w; ++x){
   
				for(k= 0; k < p.c; ++k){
   
					disp->imageData[y*step + x*p.c + k] = (unsigned char)(get_pixel(copy,x,y,k)*255);
				}
			}
		}
		return disp;
}

并在demo.c中添加函数声明IplImage* Image_to_iplimage(image im, IplImage* img);
这个函数是用来修改iamge im的格式
源代码中image结构体对图片的保存时一维的,需要修改成为图片格式转为IplImage用于opencv输出
然后就是修改image.c代码了

void draw_detections_v3(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output)
{
   
    int selected_detections_num;
    detection_with_class* selected_detections = get_actual_detections(dets, num, thresh, &selected_detections_num);

    // 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",
            (selected_detections[i].det.bbox.x - selected_detections[i].det.bbox.w / 2)*im.w,
                (selected_detections[i].det.bbox.y - selected_detections[i].det.bbox.h / 2)*im.h,
                selected_detections[i].det.bbox.w*im.w, 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
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值