看这里demo的函数定义:
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes, int avgframes,
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int dontdraw_bbox, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host,
int benchmark, int benchmark_layers)
它没有名为-out 的参数。
如果您想使用演示,使用现有代码,您有两种选择:
- 将结果保存到视频文件:
-out_filename res.avi
- 使用您的软件或 Web 浏览器通过网络在线获取结果:
-json_port 8070 -mjpeg_port 8090
现有代码 -out 仅与 detector test 一起提供。来自this函数定义:
void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh,
float hier_thresh, int dont_show, int ext_output, int save_labels, char *outfile, int letter_box, int benchmark_layers)
处理图像列表data/train.txt并将检测结果保存到result.json文件:
./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < data/train.txt
请注意,这是为了对一组输入图像进行检测并将结果保存到json。
检查here 以获取所有可能的命令以及标志和参数,它们的用法已得到很好的解释。
如果您想对输入视频进行检测并将预测保存为json,您有两种选择:
- 使用 opencv 将视频转换为一组输入图像并使用以下命令:
./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < data/train.txt
- 更改代码以在演示中包含
-out 功能:
您需要在demo.h、yolo.c、detector.c、demo.c - 1 和demo.c - 2 的演示函数中包含此参数:
`char *outfile`
将以下代码sn-p添加到demo.c:
FILE* json_file = NULL;
if (outfile) {
json_file = fopen(outfile, "wb");
if(!json_file) {
error("fopen failed");
}
char *tmp = "[\n";
fwrite(tmp, sizeof(char), strlen(tmp), json_file);
}
添加这个sn-p here:
if (json_file) {
if (json_buf) {
char *tmp = ", \n";
fwrite(tmp, sizeof(char), strlen(tmp), json_file);
}
++json_image_id;
json_buf = detection_to_json(dets, nboxes, l.classes, names, json_image_id, input);
fwrite(json_buf, sizeof(char), strlen(json_buf), json_file);
free(json_buf);
}
关闭json文件here:
if (json_file) {
char *tmp = "\n]";
fwrite(tmp, sizeof(char), strlen(tmp), json_file);
fclose(json_file);
}