Windows环境下yolov3处理多张图片

1在detector.c文件里找到test_detector函数

修改为:

		double time;
		char buff[256];
		char *input = buff;
		int j, i;
		float nms = .45;    // 0.4F
		if (filename) {
			strncpy(input, filename, 256);
			list *plist = get_paths(input);
			char **paths = (char **)list_to_array(plist);
			printf("Start Testing!\n");
			int m = plist->size;

			for (i = 0; i < m; ++i) {
				char *path = paths[i];
				image im = load_image(path, 0, 0, net.c);
				int letterbox = 0;
				image sized = resize_image(im, net.w, net.h);
				//image sized = letterbox_image(im, net.w, net.h); letterbox = 1;
				layer l = net.layers[net.n - 1];
				float *X = sized.data;
				double time = what_time_is_it_now();
				network_predict(net, X);
				printf("%s: Predicted in %lf milli-seconds.\n", input, ((double)what_time_is_it_now() - time) / 1000);
				printf("Try Very Hard:");
				printf("%s: Predicted in %lf milli-seconds.\n", path, ((double)what_time_is_it_now() - time) / 1000);
				int nboxes = 0;
				detection *dets = get_network_boxes(&net, im.w, im.h, thresh, hier_thresh, 0, 1, &nboxes, letterbox);
				if (nms) do_nms_sort(dets, nboxes, l.classes, nms);
				draw_detections_v3(im, dets, nboxes, thresh, names, alphabet, l.classes, ext_output);

				char b[2048];
				sprintf(b, "E:\\darknet-master1\\build\\darknet\\X64\\pictest2\\%d", i); //这里换上自己的路径,即你希望生成图片所保存的位置
					save_image(im, b);
				printf("save %s successfully!\n", b);

				if (save_labels)
				{
					char labelpath[4096];
					replace_image_to_label(input, labelpath);
					FILE* fw = fopen(labelpath, "wb");
					int i;
					for (i = 0; i < nboxes; ++i) {
						char buff[1024];
						int class_id = -1;
						float prob = 0;
						for (j = 0; j < l.classes; ++j) {
							if (dets[i].prob[j] > thresh && dets[i].prob[j] > prob) {
								prob = dets[i].prob[j];
								class_id = j;
							}
						}
						if (class_id >= 0) {
							sprintf(buff, "%d %2.4f %2.4f %2.4f %2.4f\n", class_id, dets[i].bbox.x, dets[i].bbox.y, dets[i].bbox.w, dets[i].bbox.h);
							fwrite(buff, sizeof(char), strlen(buff), fw);
						}
					}
					fclose(fw);
				}

				free_detections(dets, nboxes);
				free_image(im);
				free_image(sized);
				//free(boxes);
				//free_ptrs((void **)probs, l.w*l.h*l.n);
			}
		}

		printf("All Done!\n");
		system("pause");
		exit(0);

		free_ptrs(names, net.layers[net.n - 1].classes);
		free_list_contents_kvp(options);
		free_list(options);

		const int nsize = 8;
		for (j = 0; j < nsize; ++j) {
			for (i = 32; i < 127; ++i) {
				free_image(alphabet[j][i]);
			}
			free(alphabet[j]);
		}

		free(alphabet);
		free_network(net);
		printf("All Done!\n");
		system("pause");

注意:要注释掉下面的else,否则会报错。
然后重新生成。

2创建相关文件

用该文件夹下的v_img.exe把该文件下的所有视频文件截成图像
在picture文件夹下放入批量处理的图片
在这里插入图片描述
创建pictest2文件夹放检测后的图片
创建input_image_list.txt放图片的绝对路径
在这里插入图片描述
运行命令

.\darknet.exe detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights (...input_image_list.txt)  

完成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值