Darknet: Crop object detected

Created on 31 May 2018  ·  59Comments  ·  Source: AlexeyAB/darknet

hello ,
How can I use the function "crop_image()" inside the function "draw_detections_cv_v3()" to crop all the object detected on a video and save them in a folder

enhancement question want enhancement

Most helpful comment

@james203198191

  1. Did you uncomment these lines? https://github.com/AlexeyAB/darknet/blob/a720bf74e233c956e5281871ede722a2c7cf54db/src/image.c#L520-L534
  1. Did you create this folder result_img ?

  2. Did you run exactly this command?
    ./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights test.mp4

And you didn't get images img_<frame_id>_<img_id>_<class_id>.jpg in the result_img folder?

All 59 comments

@halimB8 Hi,

  1. Just un-comment these lines: https://github.com/AlexeyAB/darknet/blob/a720bf74e233c956e5281871ede722a2c7cf54db/src/image.c#L520-L534

  2. Recompile Darknet

  3. Create result_img directory near with darknet-executable file
  4. Run darknet on the video file:
    ./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights test.mp4
  5. Look at the result_img directory
    You will see files like img_<frame_id>_<img_id>_<class_id>.jpg with cropped detected objects.

About it: https://github.com/AlexeyAB/darknet/issues/846#issuecomment-390785676

it works
thank you so much :)

@james203198191 What do you mean? What error did you get?

@james203198191

  1. Did you uncomment these lines? https://github.com/AlexeyAB/darknet/blob/a720bf74e233c956e5281871ede722a2c7cf54db/src/image.c#L520-L534
  1. Did you create this folder result_img ?

  2. Did you run exactly this command?
    ./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights test.mp4

And you didn't get images img_<frame_id>_<img_id>_<class_id>.jpg in the result_img folder?

i solved it
thank you for your reply

I uncommented the above lines. However folder result_img is empty. I ran following command
./darknet detector test data/obj.data cfg/yolov3-tiny-obj.cfg /backup/yolov3-tiny.weights 1.jpeg

@dfsaw
Currently it is implemented for video only (not for images):
./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights test.mp4

@AlexeyAB okay. is there any way i can get coordinates of all detected objects in a text file

"./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights test.mp4 " for the above command the coco.data file is in cfg folder and not data.Also i am gettting error of demo needs opencv for webcam images

@rachana88
Yes, use cfg/coco.data instead of data/coco.data. And you should have your own video file test.mp4
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights test.mp4

ok, thanks!!

But Getting the same error of "

Demo needs OpenCV for webcam images

On Thu, Sep 13, 2018 at 2:05 PM Alexey notifications@github.com wrote:

@rachana88 https://github.com/rachana88
Yes, use cfg/coco.data instead of data/coco.data. And you should have your
own video file test.mp4
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights
test.mp4


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954#issuecomment-421152916,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ai-bMQltJT0FzpcC2MY4pgkYc58PwmrRks5uasiLgaJpZM4UVaaI
.

--
Rachana R. Desai
Data scientist
Cisco

ok, thanks!!

But Getting the same error of "
Demo needs OpenCV for webcam images

@rachana88
Yes, you should compile Darknet with OPENCV=1 in the Makefile. For this OpenCV should be installed: https://opencv.org/releases.html
OpenCV 3.3.0 or lower.

Without OpenCV you can't detect on video.

SO, i am sorry but now getting the error of "(Demo:392): Gtk-WARNING **: cannot open display:
"

add "-dont-show" in the end of your command to don't display the video

Hello,
Sorry but having the same error!!

(Demo:805): Gtk-WARNING **: cannot open display:

On Fri, Sep 14, 2018 at 2:59 AM halimB8 notifications@github.com wrote:

add "-dont-show" in the end of your command to don't display the video


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954#issuecomment-421302396,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ai-bMXuR1qqqetIslZKWGZ7O1aby87Ffks5ua334gaJpZM4UVaaI
.

--
Rachana R. Desai
Data scientist
Cisco

How can i crop yolo annotated bounding box result image. is there any way to do that

How can i crop yolo annotated bounding box result image. is there any way to do that

Found the Solution
add these line after 448

             image c1 = crop_image(im, left, top, right-left, bot-top);
         save_image(c1, "99");

@AlexeyAB @nwthilina I made the changes as u suggested and now the detected images are saved in results_img folder. Thanks for the option.
Is it possible to only save the images on the basis of a flag ? Now it saves whenever we run a video and it would be really great to save detected images only when activated with a flag.
is there any option for that ? If not , is it possible achieve this only by editing image.c accordingly ?

@AlexeyAB
Video-stream stoped!
Stream closed.
Video-stream stoped!
Stream closed.
Segmentation fault (core dumped)
this is the error i am getting...help needed!
i followed all the steps you said.

How about the crop object detected in python?

How can i crop yolo annotated bounding box result image. is there any way to do that

Found the Solution
add these line after 448

             image c1 = crop_image(im, left, top, right-left, bot-top);
       save_image(c1, "99");

Hello , I also have the same task, can you guide, please? I am using a single image and single object detection (LCD detection and cropping)

How can i crop yolo annotated bounding box result image. is there any way to do that

Found the Solution
add these line after 448

             image c1 = crop_image(im, left, top, right-left, bot-top);
         save_image(c1, "99");

Hello , I also have the same task, can you guide, please? I am using a single image and single object detection (LCD detection and cropping)

In which file i should wite these two lines?

U should code in image.c file

On Tue, 18 Jun 2019, 15:51 MuhammadAsadJaved, notifications@github.com
wrote:

How can i crop yolo annotated bounding box result image. is there any way
to do that

Found the Solution
add these line after 448

         image c1 = crop_image(im, left, top, right-left, bot-top);
   save_image(c1, "99");

Hello , I also have the same task, can you guide, please? I am using a
single image and single object detection (LCD detection and cropping)

In which file i should wite these two lines?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954?email_source=notifications&email_token=AECBIXMMMUEC4RMTNFW2CWDP3CZKXA5CNFSM4FCVU2EKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODX55NVY#issuecomment-503043799,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AECBIXND7AIBELX5FBIAJFTP3CZKXANCNFSM4FCVU2EA
.

@nwthilina
Sir my code differ from your's, maybe it's updated version. I have this code at line 448, Can you send me the function name and some lines of code from function after which I should put these two lines? I have tried these lines at the end of this function. also after line 448, but it still show the same output.

void draw_detections(image im, int num, float thresh, box boxes, float *probs, char *names, image *alphabet, int classes)
{
int i;

for(i = 0; i < num; ++i){
    int class_id = max_index(probs[i], classes);
    float prob = probs[i][class_id];
    if(prob > thresh){

        //// for comparison with OpenCV version of DNN Darknet Yolo v2
        //printf("\n %f, %f, %f, %f, ", boxes[i].x, boxes[i].y, boxes[i].w, boxes[i].h);
        // int k;
        //for (k = 0; k < classes; ++k) {
        //    printf("%f, ", probs[i][k]);
        //}
        //printf("\n");

448 line>> int width = im.h * .012;

        if(0){
            width = pow(prob, 1./2.)*10+1;
            alphabet = 0;
        }

        int offset = class_id*123457 % classes;
        float red = get_color(2,offset,classes);
        float green = get_color(1,offset,classes);
        float blue = get_color(0,offset,classes);
        float rgb[3];

        //width = prob*20+2;

        rgb[0] = red;
        rgb[1] = green;
        rgb[2] = blue;
        box b = boxes[i];

        int left  = (b.x-b.w/2.)*im.w;
        int right = (b.x+b.w/2.)*im.w;
        int top   = (b.y-b.h/2.)*im.h;
        int bot   = (b.y+b.h/2.)*im.h;

        if(left < 0) left = 0;
        if(right > im.w-1) right = im.w-1;
        if(top < 0) top = 0;
        if(bot > im.h-1) bot = im.h-1;
        printf("%s: %.0f%%", names[class_id], prob * 100);

        //printf(" - id: %d, x_center: %d, y_center: %d, width: %d, height: %d",
        //    class_id, (right + left) / 2, (bot - top) / 2, right - left, bot - top);

        printf("\n");
        draw_box_width(im, left, top, right, bot, width, red, green, blue);
        if (alphabet) {
            image label = get_label(alphabet, names[class_id], (im.h*.03)/10);
            draw_label(im, top + width, left, label, rgb);
            image c1 = crop_image(im, left, top, right-left, bot-top);
            save_image(c1, "99");
        }
    }
}

}

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);
}
}
}

// image output
qsort(selected_detections, selected_detections_num,

sizeof(*selected_detections), compare_by_probs);
for (i = 0; i < selected_detections_num; ++i) {
int width = im.h * .006;
if (width < 1)
width = 1;

        /*
        if(0){
        width = pow(prob, 1./2.)*10+1;
        alphabet = 0;
        }
        */

        //printf("%d %s: %.0f%%\n", i,

names[selected_detections[i].best_class], prob*100);
int offset = selected_detections[i].best_class * 123457 %
classes;
float red = get_color(2, offset, classes);
float green = get_color(1, offset, classes);
float blue = get_color(0, offset, classes);
float rgb[3];

        //width = prob*20+2;

        rgb[0] = red;
        rgb[1] = green;
        rgb[2] = blue;
        box b = selected_detections[i].det.bbox;
        printf("%f %f %f %f\n", b.x, b.y, b.w, b.h);

        int left = (b.x - b.w / 2.)*im.w;
        int right = (b.x + b.w / 2.)*im.w;
        int top = (b.y - b.h / 2.)*im.h;
        int bot = (b.y + b.h / 2.)*im.h;

        if (left < 0) left = 0;
        if (right > im.w - 1) right = im.w - 1;
        if (top < 0) top = 0;
        if (bot > im.h - 1) bot = im.h - 1;

        //int b_x_center = (left + right) / 2;
        //int b_y_center = (top + bot) / 2;
        //int b_width = right - left;
        //int b_height = bot - top;
        //sprintf(labelstr, "%d x %d - w: %d, h: %d", b_x_center,

b_y_center, b_width, b_height);

        printf("Cropping Vehicle Plate");
        draw_box_width(im, left, top, right, bot, width, red, green,

blue);
image c1 = crop_image(im, left, top, right-left, bot-top);
save_image(c1, "crop_plate");

         if (alphabet) {
            char labelstr[4096] = { 0 };
            strcat(labelstr, names[selected_detections[i].best_class]);
            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);
}
if (selected_detections[i].det.mask) {
image mask = float_to_image(14, 14, 1,
selected_detections[i].det.mask);
image resized_mask = resize_image(mask, b.w
im.w, b.h*im.h);
image tmask = threshold_image(resized_mask, .5);
embed_image(tmask, im, left, top);
free_image(mask);
free_image(resized_mask);
free_image(tmask);
}
}
free(selected_detections);
}

or use attached image.c file

Thilina Nuwan Rathnayaka

Mob : (+094)773714989

On Wed, Jun 19, 2019 at 8:40 AM MuhammadAsadJaved notifications@github.com
wrote:

@nwthilina https://github.com/nwthilina
Sir my code differ from your's, maybe it's updated version. I have this
code at line 448, Can you send me the function name and some lines of code
from function after which I should put these two lines? I have tried these
lines at the end of this function. also after line 448, but it still show
the same output.

void draw_detections(image im, int num, float thresh, box boxes, float
*
probs, char *names, image *alphabet, int classes)
{
int i;

for(i = 0; i < num; ++i){
int class_id = max_index(probs[i], classes);
float prob = probs[i][class_id];
if(prob > thresh){

    //// for comparison with OpenCV version of DNN Darknet Yolo v2
    //printf("\n %f, %f, %f, %f, ", boxes[i].x, boxes[i].y, boxes[i].w, boxes[i].h);
    // int k;
    //for (k = 0; k < classes; ++k) {
    //    printf("%f, ", probs[i][k]);
    //}
    //printf("\n");

448 line>> int width = im.h * .012;

    if(0){
        width = pow(prob, 1./2.)*10+1;
        alphabet = 0;
    }

    int offset = class_id*123457 % classes;
    float red = get_color(2,offset,classes);
    float green = get_color(1,offset,classes);
    float blue = get_color(0,offset,classes);
    float rgb[3];

    //width = prob*20+2;

    rgb[0] = red;
    rgb[1] = green;
    rgb[2] = blue;
    box b = boxes[i];

    int left  = (b.x-b.w/2.)*im.w;
    int right = (b.x+b.w/2.)*im.w;
    int top   = (b.y-b.h/2.)*im.h;
    int bot   = (b.y+b.h/2.)*im.h;

    if(left < 0) left = 0;
    if(right > im.w-1) right = im.w-1;
    if(top < 0) top = 0;
    if(bot > im.h-1) bot = im.h-1;
    printf("%s: %.0f%%", names[class_id], prob * 100);

    //printf(" - id: %d, x_center: %d, y_center: %d, width: %d, height: %d",
    //    class_id, (right + left) / 2, (bot - top) / 2, right - left, bot - top);

    printf("\n");
    draw_box_width(im, left, top, right, bot, width, red, green, blue);
    if (alphabet) {
        image label = get_label(alphabet, names[class_id], (im.h*.03)/10);
        draw_label(im, top + width, left, label, rgb);
        image c1 = crop_image(im, left, top, right-left, bot-top);
        save_image(c1, "99");
    }
}

}

}


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954?email_source=notifications&email_token=AECBIXIHF3YJIPL63KYL2KLP3GPSNA5CNFSM4FCVU2EKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYARSTI#issuecomment-503388493,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AECBIXOYHHI6R3BRAKCULP3P3GPSNANCNFSM4FCVU2EA
.

@halimB8 Hi,

  1. Just un-comment these lines: https://github.com/AlexeyAB/darknet/blob/a720bf74e233c956e5281871ede722a2c7cf54db/src/image.c#L520-L534
  2. Recompile Darknet
  3. Create result_img directory near with darknet-executable file
  4. Run darknet on the video file:
    ./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights test.mp4
  5. Look at the result_img directory
    You will see files like img_<frame_id>_<img_id>_<class_id>.jpg with cropped detected objects.

About it: #846 (comment)

I tried to recompile Darknet but I got the foloowing error:
In function ‘void draw_detections_cv_v3(mat_cv, detection, int, float, char, image, int, int)’:
./src/image_opencv.cpp:972:81: error: ‘class cv::Mat’ has no member named ‘width’
if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show
^
compilation terminated due to -Wfatal-errors.
Makefile:149: recipe for target 'obj/image_opencv.o' failed
make: * [obj/image_opencv.o] Error 1

I already tried to solve but I was unsuccessful. It seems everyone could run after un-coment these lines. Any idea what's going on?

@AlexeyAB Does something changed from 2018 to now ?? I can't get the output images in result_img folder after recompile the code !!

It works fine with the release from 7 June 2018: https://github.com/AlexeyAB/darknet/releases

However, it is still not working with the actual version using image_opencv.cpp

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.wim.w, selected_detections[i].det.bbox.him.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); } } } // image output qsort(selected_detections, selected_detections_num, sizeof(selected_detections), compare_by_probs); for (i = 0; i < selected_detections_num; ++i) { int width = im.h * .006; if (width < 1) width = 1; /* if(0){ width = pow(prob, 1./2.)10+1; alphabet = 0; } */ //printf("%d %s: %.0f%%\n", i, names[selected_detections[i].best_class], prob100); int offset = selected_detections[i].best_class * 123457 % classes; float red = get_color(2, offset, classes); float green = get_color(1, offset, classes); float blue = get_color(0, offset, classes); float rgb[3]; //width = prob20+2; rgb[0] = red; rgb[1] = green; rgb[2] = blue; box b = selected_detections[i].det.bbox; printf("%f %f %f %f\n", b.x, b.y, b.w, b.h); int left = (b.x - b.w / 2.)im.w; int right = (b.x + b.w / 2.)im.w; int top = (b.y - b.h / 2.)im.h; int bot = (b.y + b.h / 2.)im.h; if (left < 0) left = 0; if (right > im.w - 1) right = im.w - 1; if (top < 0) top = 0; if (bot > im.h - 1) bot = im.h - 1; //int b_x_center = (left + right) / 2; //int b_y_center = (top + bot) / 2; //int b_width = right - left; //int b_height = bot - top; //sprintf(labelstr, "%d x %d - w: %d, h: %d", b_x_center, b_y_center, b_width, b_height); printf("Cropping Vehicle Plate"); draw_box_width(im, left, top, right, bot, width, red, green, blue); image c1 = crop_image(im, left, top, right-left, bot-top); save_image(c1, "crop_plate"); if (alphabet) { char labelstr[4096] = { 0 }; strcat(labelstr, names[selected_detections[i].best_class]); 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); } if (selected_detections[i].det.mask) { image mask = float_to_image(14, 14, 1, selected_detections[i].det.mask); image resized_mask = resize_image(mask, b.wim.w, b.him.h); image tmask = threshold_image(resized_mask, .5); embed_image(tmask, im, left, top); free_image(mask); free_image(resized_mask); free_image(tmask); } } free(selected_detections); } or use attached image.c file Thilina Nuwan Rathnayaka Mob : (+094)773714989

On Wed, Jun 19, 2019 at 8:40 AM MuhammadAsadJaved
@.> wrote: @nwthilina https://github.com/nwthilina Sir my code differ from your's, maybe it's updated version. I have this code at line 448, Can you send me the function name and some lines of code from function after which I should put these two lines? I have tried these lines at the end of this function. also after line 448, but it still show the same output. void draw_detections(image im, int num, float thresh, box *boxes, float *probs, char *names, image *alphabet, int classes) { int i; for(i = 0; i < num; ++i){ int class_id = max_index(probs[i], classes); float prob = probs[i][class_id]; if(prob > thresh){ //// for comparison with OpenCV version of DNN Darknet Yolo v2 //printf("\n %f, %f, %f, %f, ", boxes[i].x, boxes[i].y, boxes[i].w, boxes[i].h); // int k; //for (k = 0; k < classes; ++k) { // printf("%f, ", probs[i][k]); //} //printf("\n"); 448 line>> int width = im.h * .012; if(0){ width = pow(prob, 1./2.)10+1; alphabet = 0; } int offset = class_id123457 % classes; float red = get_color(2,offset,classes); float green = get_color(1,offset,classes); float blue = get_color(0,offset,classes); float rgb[3]; //width = prob20+2; rgb[0] = red; rgb[1] = green; rgb[2] = blue; box b = boxes[i]; int left = (b.x-b.w/2.)im.w; int right = (b.x+b.w/2.)im.w; int top = (b.y-b.h/2.)im.h; int bot = (b.y+b.h/2.)im.h; if(left < 0) left = 0; if(right > im.w-1) right = im.w-1; if(top < 0) top = 0; if(bot > im.h-1) bot = im.h-1; printf("%s: %.0f%%", names[class_id], prob * 100); //printf(" - id: %d, x_center: %d, y_center: %d, width: %d, height: %d", // class_id, (right + left) / 2, (bot - top) / 2, right - left, bot - top); printf("\n"); draw_box_width(im, left, top, right, bot, width, red, green, blue); if (alphabet) { image label = get_label(alphabet, names[class_id], (im.h.03)/10); draw_label(im, top + width, left, label, rgb); image c1 = crop_image(im, left, top, right-left, bot-top); save_image(c1, "99"); } } } } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#954?email_source=notifications&email_token=AECBIXIHF3YJIPL63KYL2KLP3GPSNA5CNFSM4FCVU2EKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYARSTI#issuecomment-503388493>, or mute the thread https://github.com/notifications/unsubscribe-auth/AECBIXOYHHI6R3BRAKCULP3P3GPSNANCNFSM4FCVU2EA .

dear sir:
i tried your code, but no result output. can you help me?

I un-comment following lines:
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);

I also added following lines
image c1 = crop_image(im, left, top, right-left, bot-top);
save_image(c1, "99");

But I am getting no image in result_img folder for my videos but getting images when I am testing on single images. Please help me

Facing the same problem too. Anyone can help?

@AlexeyAB Can you help? I can't save the cropped image of detected object from video. It can only works in images.

Did you recompile project after changes ?

On Wed, Feb 12, 2020 at 9:39 PM xinyee1997 notifications@github.com wrote:

@AlexeyAB https://github.com/AlexeyAB Can you help? I can't save the
cropped image of detected object from video. It can only works in images.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954?email_source=notifications&email_token=AG4GR5E5HOBVMEA33GG4V7LRCP3Z3A5CNFSM4FCVU2EKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELQZMUI#issuecomment-585209425,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AG4GR5FNXONBBAKHTMP5WC3RCP3Z3ANCNFSM4FCVU2EA
.

@MuhammadAsadJaved Yes. I faced the problem like @Pulkitg64 stated.
Are you able to crop detected objects from video? Can you guide us how to do so?

@xinyee1997 我还在图像上进行了测试,但没有在视频上进行尝试。

Did you recompile project after changes ?

On Wed, Feb 12, 2020 at 9:39 PM xinyee1997 @.*> wrote: @AlexeyAB https://github.com/AlexeyAB Can you help? I can't save the cropped image of detected object from video. It can only works in images. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#954?email_source=notifications&email_token=AG4GR5E5HOBVMEA33GG4V7LRCP3Z3A5CNFSM4FCVU2EKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELQZMUI#issuecomment-585209425>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG4GR5FNXONBBAKHTMP5WC3RCP3Z3ANCNFSM4FCVU2EA .

Yes I recompiled the project but works only for images

@halimB8 Hi,

  1. Just un-comment these lines: https://github.com/AlexeyAB/darknet/blob/a720bf74e233c956e5281871ede722a2c7cf54db/src/image.c#L520-L534
  2. Recompile Darknet
  3. Create result_img directory near with darknet-executable file
  4. Run darknet on the video file:
    ./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights test.mp4
  5. Look at the result_img directory
    You will see files like img_<frame_id>_<img_id>_<class_id>.jpg with cropped detected objects.

About it: #846 (comment)

I tried without success. I used this repo, https://github.com/AlexeyAB/darknet/blob/master/src/image.c, but I guess it's different. Please anybody has solved this?

Can anyone help?

can someone provide me with an edited image.c that converted rectangle box to circle box detection..

Hello. This code is exactly what I need.. but after reading the entire thread it seems some sort of update has knocked the code out of commission? Any luck? anybody?

The code is changed recently I’ll try to send you old version.

On Sun, Jun 7, 2020 at 5:37 AM Sceptersax notifications@github.com wrote:

Hello. This code is exactly what I need.. but after reading the entire
thread it seems some sort of update has knocked the code out of commission?
Any luck? anybody?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954#issuecomment-640121311,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AG4GR5CLZQSY46YI5KJGZ3TRVKZIJANCNFSM4FCVU2EA
.

Give me your email address please

On Sun, Jun 7, 2020 at 5:37 AM Sceptersax notifications@github.com wrote:

Hello. This code is exactly what I need.. but after reading the entire
thread it seems some sort of update has knocked the code out of commission?
Any luck? anybody?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954#issuecomment-640121311,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AG4GR5CLZQSY46YI5KJGZ3TRVKZIJANCNFSM4FCVU2EA
.

Here is my email for anyone that have the converted rectangle box to circle box code for image.c. thanks. [email protected]

It should not be that difficult, just change the “draw rectangular “
function to draw circle accordingly. You can see opencv draw circle
function.

On Sun, Jun 7, 2020 at 2:32 PM larrywal-express notifications@github.com
wrote:

Here is my email for anyone that have the converted rectangle box to
circle box code for image.c. thanks. [email protected]


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954#issuecomment-640165209,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AG4GR5CXJYDOB433HPKQBP3RVMX6NANCNFSM4FCVU2EA
.

I mean for the draknet folder for Yolo. the image.c file inside the src

I also said same. You just need to change “cv2rectangular function to
cv2circle . Keep other things same.

You can also try this project, it’s relatively easy to change

https://github.com/ultralytics/yolov3

On Sun, Jun 7, 2020 at 2:54 PM larrywal-express notifications@github.com
wrote:

I mean for the draknet folder for Yolo. the image.c file inside the src


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954#issuecomment-640167398,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AG4GR5HPW2ILGIVKYYVF2NDRVM2RFANCNFSM4FCVU2EA
.

Thanks. can you provide me the location of where to change? because I wouldn't see the cv2.rectangle function in image.c or you you can provide me where to change in the recommend project.

@ MuhammadAsadJaved Hello,

I could still use the code. I attempted to contact you but didn't hear back. My email is:

[email protected]

Thanks

@ MuhammadAsadJaved Hello,

I could still use the code. I attempted to contact you but didn't hear back. My email is:

[email protected]

Thanks

OK. I will send you image.c file, you can try to use this image.c file.

Note: Do not delete original image.c file, copy or rename it for backup.
I tested it only on image input, not on video.

thanks. I send it to your email.

Will do. Thanks

On Sun, Jun 14, 2020 at 10:54 PM Asad notifications@github.com wrote:

@ MuhammadAsadJaved Hello,

I could still use the code. I attempted to contact you but didn't hear
back. My email is:

[email protected]

Thanks

OK. I will send you image.c file, you can try to use this image.c file.

Note: Do not delete original image.c file, copy or rename it for backup.
I tested it only on image input, not on video.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/AlexeyAB/darknet/issues/954#issuecomment-643918204,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AC2UHTBVKH3UBYZ52VDWN2TRWWZPZANCNFSM4FCVU2EA
.

I had some issues with my setup and couldn’t recompile the make file so I had to reinstall everything.. now I’m having other issues..

I wish to implement the cropping implementation into the image.c file but now I’m thinking I have the wrong opencv version. Currently I have opencv 3.6.

What version should I have?

@AlexeyAB i have cropped detetcted part successfully and rsult is stored in result_img but when i am trying to show that image using opencv its giving me error as : AttributeError: 'NoneType' object has no attribute 'clip'
image exist but showing me this error. image size is small just 2.4kb only and dim 89x76.
what should i do?

In order to crop multiple objects having different labels in a single image, replace "image.c" file in "src" folder with my image.c file. It will crop the detected objects and save them in .jpg format corresponding to different labels
image.zip

@halimB8 Hi,

  1. Just un-comment these lines: https://github.com/AlexeyAB/darknet/blob/a720bf74e233c956e5281871ede722a2c7cf54db/src/image.c#L520-L534
  2. Recompile Darknet
  3. Create result_img directory near with darknet-executable file
  4. Run darknet on the video file:
    ./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights test.mp4
  5. Look at the result_img directory
    You will see files like img_<frame_id>_<img_id>_<class_id>.jpg with cropped detected objects.

About it: #846 (comment)

i am still not getting images in the result_img folder..plz help me out

sorry for the earlier query..
I am still not getting the images in the result_img folder..plz help me out

Works great for saving the jpg images in result_img, though png is desired.
For now added a line to print the bounding box coordinates, to allow for python post-processing.
Would be much easier for darknet to output them.

That was easy. Changed from
save_image(cropped_im, image_name);
to
save_image_png(cropped_im, image_name);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasleen137 picture jasleen137  ·  3Comments

HanSeYeong picture HanSeYeong  ·  3Comments

PROGRAMMINGENGINEER-NIKI picture PROGRAMMINGENGINEER-NIKI  ·  3Comments

kebundsc picture kebundsc  ·  3Comments

Cipusha picture Cipusha  ·  3Comments