diff --git a/build/darknet/x64/darknet.py b/build/darknet/x64/darknet.py index 784399ee..3d885d20 100644 --- a/build/darknet/x64/darknet.py +++ b/build/darknet/x64/darknet.py @@ -278,7 +278,7 @@ netMain = None metaMain = None altNames = None -def performDetect(imagePath="data/dog.jpg", thresh= 0.25, configPath = "./cfg/yolov3.cfg", weightPath = "yolov3.weights", metaPath= "./data/coco.data", showImage= True, makeImageOnly = False, initOnly= False): +def performDetect(imagePath="data/dog.jpg", thresh= 0.25, configPath = "./cfg/yolov3.cfg", weightPath = "yolov3.weights", metaPath= "./cfg/coco.data", showImage= True, makeImageOnly = False, initOnly= False): """ Convenience function to handle the detection and returns of objects. diff --git a/build/darknet/x64/darknet_many_images.cmd b/build/darknet/x64/darknet_many_images.cmd index a763d022..95eba449 100644 --- a/build/darknet/x64/darknet_many_images.cmd +++ b/build/darknet/x64/darknet_many_images.cmd @@ -1,4 +1,4 @@ -darknet.exe detector test data/voc.data cfg/yolov2-voc.cfg yolo-voc.weights -ext_output -dont_show < data/train.txt > result.txt +darknet.exe detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights -ext_output -dont_show < data/train.txt > result.txt pause \ No newline at end of file diff --git a/src/demo.c b/src/demo.c index 7481660e..d57fae40 100644 --- a/src/demo.c +++ b/src/demo.c @@ -51,6 +51,7 @@ static float *avg; void draw_detections_cv(IplImage* show_img, int num, float thresh, box *boxes, float **probs, char **names, image **alphabet, int classes); void draw_detections_cv_v3(IplImage* show_img, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output); void show_image_cv_ipl(IplImage *disp, const char *name); +void save_cv_png(IplImage *img, const char *name); image get_image_from_stream_resize(CvCapture *cap, int w, int h, int c, IplImage** in_img, int cpp_video_capture, int dont_close); image get_image_from_stream_letterbox(CvCapture *cap, int w, int h, int c, IplImage** in_img, int cpp_video_capture, int dont_close); int get_stream_fps(CvCapture *cap, int cpp_video_capture); @@ -264,7 +265,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int }else{ char buff[256]; sprintf(buff, "%s_%08d.jpg", prefix, count); - cvSaveImage(buff, show_img, 0); + save_cv_png(buff, show_img); + //cvSaveImage(buff, show_img, 0); //save_image(disp, buff); } diff --git a/src/image.c b/src/image.c index 0a97b83e..06112cb4 100644 --- a/src/image.c +++ b/src/image.c @@ -315,6 +315,9 @@ int compare_by_probs(const void *a_ptr, const void *b_ptr) { void draw_detections_v3(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output) { + static int frame_id = 0; + frame_id++; + int selected_detections_num; detection_with_class* selected_detections = get_actual_detections(dets, num, thresh, &selected_detections_num, names); @@ -384,6 +387,23 @@ void draw_detections_v3(image im, detection *dets, int num, float thresh, char * //int b_height = bot - top; //sprintf(labelstr, "%d x %d - w: %d, h: %d", b_x_center, b_y_center, b_width, b_height); + // you should create directory: result_img + //static int copied_frame_id = -1; + //static image copy_img; + //if (copied_frame_id != frame_id) { + // copied_frame_id = frame_id; + // if (copy_img.data) free_image(copy_img); + // copy_img = copy_image(im); + //} + //image cropped_im = crop_image(copy_img, left, top, right - left, bot - top); + //static int img_id = 0; + //img_id++; + //char image_name[1024]; + //int best_class_id = selected_detections[i].best_class; + //sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, best_class_id, names[best_class_id]); + //save_image(cropped_im, image_name); + //free_image(cropped_im); + if (im.c == 1) { draw_box_width_bw(im, left, top, right, bot, width, 0.8); // 1 channel Black-White } @@ -480,6 +500,14 @@ void draw_detections(image im, int num, float thresh, box *boxes, float **probs, #ifdef OPENCV +void save_cv_png(IplImage *img, const char *name) +{ + IplImage* img_rgb = cvCreateImage(cvSize(img->width, img->height), 8, 3); + cvCvtColor(img, img_rgb, CV_RGB2BGR); + stbi_write_png(name, img_rgb->width, img_rgb->height, 3, (char *)img_rgb->imageData, 0); + cvRelease(&img_rgb); +} + void draw_detections_cv_v3(IplImage* show_img, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output) { int i, j; @@ -575,7 +603,7 @@ void draw_detections_cv_v3(IplImage* show_img, detection *dets, int num, float t //static int img_id = 0; //img_id++; //char image_name[1024]; - //sprintf(image_name, "result_img/img_%d_%d_%d.jpg", frame_id, img_id, class_id); + //sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); //CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); //cvSetImageROI(copy_img, rect); //cvSaveImage(image_name, copy_img, 0); @@ -774,10 +802,7 @@ void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_ int k = cvWaitKey(20); if (k == 's' || current_batch == (max_batches - 1) || current_batch % 100 == 0) { //cvSaveImage("chart.jpg", img, 0); - IplImage* img_rgb = cvCreateImage(cvSize(img->width, img->height), 8, 3); - cvCvtColor(img, img_rgb, CV_RGB2BGR); - stbi_write_png("chart.png", img_rgb->width, img_rgb->height, 3, (char *)img_rgb->imageData, 0); - cvRelease(&img_rgb); + save_cv_png("chart.png", img); cvPutText(img, "- Saved", cvPoint(250, img_size - 10), &font, CV_RGB(255, 0, 0)); } else @@ -1013,7 +1038,7 @@ void show_image_cv_ipl(IplImage *disp, const char *name) cvShowImage(buff, disp); //cvReleaseImage(&disp); } -#endif +#endif // OPENCV void show_image(image p, const char *name) { @@ -1205,30 +1230,7 @@ int get_stream_fps(CvCapture *cap, int cpp_video_capture) } return fps; } - -void save_image_jpg(image p, const char *name) -{ - image copy = copy_image(p); - if(p.c == 3) rgbgr_image(copy); - int x,y,k; - - char buff[256]; - sprintf(buff, "%s.jpg", name); - - IplImage *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); - } - } - } - cvSaveImage(buff, disp,0); - cvReleaseImage(&disp); - free_image(copy); -} -#endif +#endif // OPENCV void save_image_png(image im, const char *name) { @@ -1277,6 +1279,10 @@ void save_image(image im, const char *name) save_image_options(im, name, JPG, 80); } +void save_image_jpg(image p, const char *name) +{ + save_image_options(p, name, JPG, 80); +} void show_image_layers(image p, char *name) {