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