So I've declared two arrays like this (red, green and blue are in a structure and the head pointer is just used to locate which file I'm looking at):
Code:
int i, j, qi, qj, identify_x, identify_y;
FILE *fid;
char fnameid[100];
printf("\tEnter Input Image File Name To Perform Image detection On: \n");
scanf("%s", fnameid);
fseek(stdin,0,SEEK_END);
fid = fopen(fnameid, "r");
if (fid == NULL)
{
printf("\tError while opening the file\n");
}
else
{
printf("\tWriting in %s\n", fnameid);
}
fscanf(fid, "%s %d %d %d", head[1].filetype, &head[1].width, &head[1].height, &head[1].rgb_comp_colour);
printf("%s %d %d %d", head[1].filetype, head[1].width, head[1].height, head[1].rgb_comp_colour);
RGBArray = (PPMPixel **)malloc(head[1].height*sizeof(PPMPixel*)); //Points to malloc
if((RGBArray == NULL))
{
printf("\tError allocating memory to the array\n");
}
else
{
printf("\tMemory allocated to the PPM array sucessfully\n");
}
for (i=0;i<head[1].height;i++)
{
RGBArray[i] = (PPMPixel *)malloc(head[1].width*sizeof(PPMPixel));
}
//Initialising each element
for (j=0;j<head[1].height;j++)
{
for (i=0;i<head[1].width;i++)
{
fscanf(fid, "%d %d %d ", &q.red, &q.green, &q.blue);
PPMPixel* data = &RGBArray[j][i];
data->red = q.red;
data->green = q.green;
data->blue = q.blue;
}
}
FILE *fq;
char fnameq[100];
printf("\tEnter Query Image File Name: \n");
scanf("%s", fnameq);
fseek(stdin,0,SEEK_END);
fq = fopen(fnameq, "r");
if (fq == NULL)
{
printf("\tError while opening the file\n");
}
else
{
printf("\tWriting in %s\n", fnameq);
}
fscanf(fq, "%s %d %d %d", head[2].filetype, &head[2].width, &head[2].height, &head[2].rgb_comp_colour);
printf("%s %d %d %d", head[2].filetype, head[2].width, head[2].height, head[2].rgb_comp_colour);
QueryArray = (PPMPixel **)malloc(head[2].height*sizeof(PPMPixel*)); //Points to malloc
if((QueryArray == NULL))
{
printf("\tError allocating memory to the array\n");
}
else
{
printf("\tMemory allocated to the PPM array sucessfully\n");
}
for (qi=0;qi<head[2].height;qi++)
{
QueryArray[qi] = (PPMPixel *)malloc(head[2].width*sizeof(PPMPixel));
}
//Initialising each element
for (qj=0;qj<head[2].height;qj++)
{
for (qi=0;qi<head[2].width;qi++)
{
fscanf(fq, "%d %d %d ", &r.red, &r.green, &r.blue);
PPMPixel* data = &QueryArray[qj][qi];
data->red = r.red;
data->green = r.green;
data->blue = r.blue;
}
}
And I've located the query array in the RGB array like so:
Code:
int wally; //Tests if query array is found in main input array
for (int i=0;i<(head[1].width-head[2].width);i++)
{
for(int j=0;j<(head[1].height-head[2].height);j++) //
{
for(int qi=0; qi<head[2].width; qi++)
{
for(int qj=0;qj<head[2].height;qj++)
{
if ((RGBArray[i+qi][j+qj].red != QueryArray[qi][qj].red) || (RGBArray[i+qi][j+qj].green != QueryArray[qi][qj].green)
|| (RGBArray[i+qi][j+qj].blue != QueryArray[qi][qj].blue))
{
wally = FALSE;
break;
}
}
if(wally = TRUE)
identify_y = j; //Stores j values that match in variable
identify_x = i; //Stores i values that match in variable
break;
}
}
}
What I want to do is use realloc to change the values withing the RGBArray so that I can have a red box around the located query array. Thank you for any help.