Segmentation fault (core dumped)
J'ai lu le post precedent mais dans mon cas j;ai initialiser le fichier.
Voila des bouts de mon prog :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
int main(int argc, char *argv[])
{
sequence *seq; /* pointer to input sequence data structure */
image **imgs; /* pointer to input sequence array of images */
image *out; /* pointer the output image */
char seq_in[100], /* input sequence name */
seq_out[100], /* output sequence name */
file_out[100], /* output file name */
file_in[100]; /*input image to read*/
int length; /* length of the sequence */
int i=0; /* loop index */
/* Process input arguments */
if(argc != 3)
{
fprintf(stderr,"Usage: %s [input PGM sequence name] [output PGM sequence name]\n", argv[0]);
exit(0);
}
else
{
strcpy(seq_in, argv[1]);
strcpy(seq_out, argv[2]);
}
/* Load the input sequence */
seq = load_sequence(seq_in);
/* Get a pointer to the sequence images */
imgs = get_sequence_images(seq);
/* Get sequence length */
length = get_sequence_length(seq);
/* Check if sequence is long enough */
if(length < 2) {
fprintf(stderr, "sequence is too short\n");
exit(1)
pgm_read_image("mad000.pgm",imgs[0]);
out = clone_image(imgs[0]);
//
while(i!=length-1)
{
/*read the n image */
double x;
sprintf(file_in, "%s%03d.pgm", seq_in, i);
pgm_read_image(file_in,imgs[i]);
/*Idiff=In-In-1 */
create_diff_image(imgs[i],imgs[i+1],out);
x=calc_entropy_image(out,1);
printf(" entropy value : %lg ",x);
i++;
imgs[i-1]=imgs[i];
/* Now write out the diff image */
/*sprintf(file_out, "%s%03d.pgm", seq_out, i);
printf("Writing out %s\n",file_out);
pgm_write_image(out, file_out);
*/
printf("diff a la %d eme valeur\n",i);
} |
je sais que l'erreur vient de x=calc_entropy_image(out,1); . En effet si j'enleve cette fonction le programme marche .
voici le prog de cette fonction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
ouble calc_entropy_image(image *img, int minus)
{
double *prob, entropy;
pel *pdat;
int p;
pdat = get_image_pels(img);
if(minus)
{
prob = (double *)calloc(512,sizeof(double));
for(p=0;p<get_image_width(img)*get_image_height(img);p++)
prob[pdat[p]+256]++;
for(p=0;p<512;p++)
prob[p] = prob[p]/(get_image_width(img)*get_image_height(img));
entropy = 0.0;
for(p=0;p<512;p++)
if(prob[p] != 0.0)
entropy += -prob[p] * log2(prob[p]);
// printf("test into calc_entropy_image ");
}
else
{
prob = (double *)calloc(256,sizeof(double));
for(p=0;p<get_image_width(img)*get_image_height(img);p++)
prob[pdat[p]]++;
for(p=0;p<256;p++)
prob[p] = prob[p]/(get_image_width(img)*get_image_height(img));
entropy = 0.0;
for(p=0;p<256;p++)
if(prob[p] != 0.0)
entropy += -prob[p] * log2(prob[p]);
}
//printf("test into calc_entropy_image ");
free(prob);
//printf("test into calc_entropy_image\n ");
return(entropy);
} |