ZQPei / patchmatch_inpainting

Implementation of PatchMatch for image inpainting in cpp
Other
48 stars 10 forks source link

Segmentation fault #10

Closed ZQPei closed 4 years ago

ZQPei commented 4 years ago

@zvezdochiot The memory will overflow if proceeding mounts of images in one program. How to get this:

  1. First prepare a large test set of 1000 images or more. For simpility, just copy the existing test images for 400 times, the same to the masks. Rename then as image_00001.png, image_00002.png, etc.

  2. Replace the main function as what I did at the very beginning. It was tested on 12000 images with 6 group of masks. You may need modify the code below a little bit to run on your test images properly.

If you find your memory usage growing continuously, that is the implicit problem hidden in the process function which will cause segmentation fault.

int main(int argc, char** argv) {

    char image_path[100];
    char mask_path[100];
    char masked_path[100];
    char output_path[100];

    double psnr_mean[6] = {0,};
    double ssim_mean[6] = {0,};
    double time_mean[6] = {0,};

    for(int i=0;i<6;++i){
        double psnr_total = 0.0;
        double ssim_total = 0.0;
        double time_total = 0.0;
        for(int j=i*2000;j<(i+1)*2000;++j){
            sprintf(image_path, "../image_files/inpainting/image/image_%05d.png", j);
            sprintf(mask_path, "../image_files/inpainting/mask/mask_%05d.png", j);
            sprintf(masked_path, "../image_files/inpainting/masked_image/masked_image_%05d.png", j);
            sprintf(output_path, "../image_files/inpainting/output/output_%05d.png", j);

            process(image_path, mask_path, output_path, &psnr_total, &ssim_total, &time_total);
        }
        psnr_mean[i] = psnr_total/2000.0;
        ssim_mean[i] = ssim_total/2000.0;
        time_mean[i] = time_total/2000.0;
        printf("[%02d%% - %02d%%] average psnr: %lf\taverage ssim: %lf\taverage time: %lf\n", i*10, (i+1)*10, psnr_mean[i], ssim_mean[i], time_mean[i]);

        FILE * fp = fopen("../image_files/inpainting/result.txt", "a");
        fprintf(fp, "[%02d%% - %02d%%] average psnr: %lf\taverage ssim: %lf\taverage time: %lf\n", i*10, (i+1)*10, psnr_mean[i], ssim_mean[i], time_mean[i]);
        fclose(fp);
    }

    for(int i=0;i<6;++i){
        printf("[%02d%% - %02d%%] average psnr: %lf\taverage ssim: %lf\taverage time: %lf\n", i*10, (i+1)*10, psnr_mean[i], ssim_mean[i], time_mean[i]);
    }

    return 0;
}
zvezdochiot commented 4 years ago

I modified it slightly so as not to mess with an array of useless files:

int main(int argc, char** argv)
{
    char image_path[100];
    char mask_path[100];
    char masked_path[100];
    char output_path[100];

    double psnr_mean[3] = {0,};
    double ssim_mean[3] = {0,};
    double time_mean[3] = {0,};

    double psnr_total = 0.0;
    double ssim_total = 0.0;
    double time_total = 0.0;

    for(int i = 0; i < 6000; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            sprintf(image_path, "../image_files/inpainting/image/image_%05d.png", j);
            sprintf(mask_path, "../image_files/inpainting/mask/mask_%05d.png", j);
            sprintf(masked_path, "../image_files/inpainting/masked_image/masked_image_%05d.png", j);
            sprintf(output_path, "../image_files/inpainting/output/output_%05d.png", j);

            process(image_path, mask_path, output_path, &psnr_total, &ssim_total, &time_total);
            psnr_mean[j] = psnr_total/6000.0;
            ssim_mean[j] = ssim_total/6000.0;
            time_mean[j] = time_total/6000.0;
        }
    }

    for(int i = 0; i < 3; ++i)
    {
        printf("[%02d%% - %02d%%] average psnr: %lf\taverage ssim: %lf\taverage time: %lf\n", i*10, (i+1)*10, psnr_mean[i], ssim_mean[i], time_mean[i]);
    }

    return 0;
}

Really, eats memory. Will seek.

zvezdochiot commented 4 years ago

https://github.com/ZQPei/patchmatch_inpainting/blob/cc1231891cac423b0fd5cd7f2259f8c506b009cd/src/main.cpp#L83

I did not find the release of memory allocated for the image after it was written to the media.

PS: Fresh yes.

zvezdochiot commented 4 years ago

Maybe add?:

    cvReleaseImage(& output_ipl_img);
ZQPei commented 4 years ago

Cool! Do the memory leaking problem solved now? I don't test, cause I dont have opencv install on my laptop now.

zvezdochiot commented 4 years ago

@ZQPei . He eats a lot. But it does not grow as before. I will wait for the tests. If all is well, do a new release (0.2). (This is important to me, I am also a maintainer).