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)
完成!