darknetのyoloはいくつかの画像をテストして結果を保存します
14257 ワード
./darknet detector test data/candle.data cfg/yolov3.cfg backup/yolov3_1000.weights 000.txt
を実行し、結果はresultsディレクトリの下に保存される.この方法は原版の2つの方法に代わることができる.ls ${PWD}/*jpg > 000.txt
を用いる、現在のディレクトリのjpgピクチャの絶対パスを000に格納することができる.txt get_image_name
void get_image_name(char *filename, char *image, int l) {
int j, i = l - 1, k = 8;
while(i > 0) {
if(filename[i] == '/') {
j = i + 1;
break;
}
--i;
}
while(j < l - 4) {
image[k] = filename[j];
++k;
++j;
}
}
test_detector
関数:while (1)
にchar lwd[256];
size_t llen = 0;
strncpy(lwd, filename, 256);
if(lwd[strlen(lwd)-1] != 't') {
printf("Need txt file of image path
");
return;
}
FILE* fl = fopen(lwd, "r");
while (1)
にif(getline(&filename, &llen, fl) == -1) {
fclose(fl);
break;
}
filename[strlen(filename)-1]='\0';
save_image(im, "predictions");
をchar lwd_name[256] = {"results/"};
get_image_name(filename, lwd_name, strlen(filename));
save_image(im, lwd_name);
show_image(im, "predictions");
wait_until_press_key_cv();
destroy_all_windows_cv();
if (filename) break;
if (alphabet) {
char labelstr[4096] = { 0 };
int lwd_score = selected_detections[i].det.prob[selected_detections[i].best_class] * 100;
char lwd_str[10];
snprintf(lwd_str, sizeof(lwd_str), "%d", lwd_score);
strcat(labelstr, names[selected_detections[i].best_class]);
strcat(labelstr, lwd_str);
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);
}