mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Now you can un-comment several lines for saving images of cropped objects to /result_img/ directory
This commit is contained in:
@ -278,7 +278,7 @@ netMain = None
|
|||||||
metaMain = None
|
metaMain = None
|
||||||
altNames = 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.
|
Convenience function to handle the detection and returns of objects.
|
||||||
|
|
||||||
|
@ -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
|
pause
|
@ -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(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 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 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_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);
|
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);
|
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{
|
}else{
|
||||||
char buff[256];
|
char buff[256];
|
||||||
sprintf(buff, "%s_%08d.jpg", prefix, count);
|
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);
|
//save_image(disp, buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
66
src/image.c
66
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)
|
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;
|
int selected_detections_num;
|
||||||
detection_with_class* selected_detections = get_actual_detections(dets, num, thresh, &selected_detections_num, names);
|
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;
|
//int b_height = bot - top;
|
||||||
//sprintf(labelstr, "%d x %d - w: %d, h: %d", b_x_center, b_y_center, b_width, b_height);
|
//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) {
|
if (im.c == 1) {
|
||||||
draw_box_width_bw(im, left, top, right, bot, width, 0.8); // 1 channel Black-White
|
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
|
#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)
|
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;
|
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;
|
//static int img_id = 0;
|
||||||
//img_id++;
|
//img_id++;
|
||||||
//char image_name[1024];
|
//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);
|
//CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y);
|
||||||
//cvSetImageROI(copy_img, rect);
|
//cvSetImageROI(copy_img, rect);
|
||||||
//cvSaveImage(image_name, copy_img, 0);
|
//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);
|
int k = cvWaitKey(20);
|
||||||
if (k == 's' || current_batch == (max_batches - 1) || current_batch % 100 == 0) {
|
if (k == 's' || current_batch == (max_batches - 1) || current_batch % 100 == 0) {
|
||||||
//cvSaveImage("chart.jpg", img, 0);
|
//cvSaveImage("chart.jpg", img, 0);
|
||||||
IplImage* img_rgb = cvCreateImage(cvSize(img->width, img->height), 8, 3);
|
save_cv_png("chart.png", img);
|
||||||
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);
|
|
||||||
cvPutText(img, "- Saved", cvPoint(250, img_size - 10), &font, CV_RGB(255, 0, 0));
|
cvPutText(img, "- Saved", cvPoint(250, img_size - 10), &font, CV_RGB(255, 0, 0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1013,7 +1038,7 @@ void show_image_cv_ipl(IplImage *disp, const char *name)
|
|||||||
cvShowImage(buff, disp);
|
cvShowImage(buff, disp);
|
||||||
//cvReleaseImage(&disp);
|
//cvReleaseImage(&disp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif // OPENCV
|
||||||
|
|
||||||
void show_image(image p, const char *name)
|
void show_image(image p, const char *name)
|
||||||
{
|
{
|
||||||
@ -1205,30 +1230,7 @@ int get_stream_fps(CvCapture *cap, int cpp_video_capture)
|
|||||||
}
|
}
|
||||||
return fps;
|
return fps;
|
||||||
}
|
}
|
||||||
|
#endif // OPENCV
|
||||||
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
|
|
||||||
|
|
||||||
void save_image_png(image im, const char *name)
|
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);
|
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)
|
void show_image_layers(image p, char *name)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user