Log in

View Full Version : How to use the data obtain in one C file to another C file?


tommy_chai
30-12-2007, 07:32
Hi guys,
First, I detect coordinates for left and right corners of a mouth in Corners.c and saved in struct Coordinate for 72 images.
How can I able to link it to another C file, let's say try5.c so that it can be used for template matching purpose when i execute 72 images in a loop in try5.c?
Sorry because I cannot provide the full program because it is a way too long to read. These are the parts which i think very important in order to solve the problem. Help from anyone will be appreciated.

Thank you very much.


Corners.c
struct Coordinate
{
int x;
int y;
};
susan_corners(in,r,bp,max_no,corner_list,x_size,y_ size){
:
:
struct Coordinate left_corner, right_corner;
}

try5.c
:
:
#define NUM 72
:
main()
{
:
:
if((fp33 = fopen("facecolor_input.dat","r")) == NULL){
printf("File input filename2 can not open\n");
exit(1);
}
for(k=0;k<NUM;k++){
fscanf(fp33,"%s",filename33[k]);
}
fclose(fp33);
:
:
for(total = 0; total<NUM; total ++){

printf("\nimage==>%d\n",(total+1));

/** read the color data from the file of input face image **/
read_data_color(filename33[total],inpcolor);
:
:
/* Template Matching */
//example for eye template matching
XX1=56; // Left X coordinate for eye template
YY1=44;
XX2=164; //right X coordinate for eye template
YY2=44;
// plf_x, plf_y, prg_x, prg_y are the left and right x & y coordinates from the full input image which has been obtained in Corners.c
affine_recog_a(plf_x, plf_y, prg_x, prg_y, XX1, YY1, XX2, YY2);
cross_correlation_recog_a(TEMPLATE_a, image_out_a, &CC1[0]);
:
:
}


Best regards,
Tommy

gnormhurst
31-12-2007, 09:34
Hi Tommy,

Perhaps you can restate your question by first indicating how you hope to have the data flow in your program. It seems to start with a file containing a list of image file names, and then each image file is read in and processed somehow. But nothing in Corners.c seems to be involved in the processing in main() in try5.c.

How does susan_corners() play a role in the flow of data? Or how would you like susan_corners() to play a role in the flow of data?

-Norm

tommy_chai
31-12-2007, 21:16
Very sorry to cause such confusion. Susan_corners() is the subroutine to get the left and right corners' x&y coordinates. My problem is to reuse the struct data(corner's coordinates)from Corners.c in another file named "try5.c". Any idea my friend?

TimCraig
31-12-2007, 21:38
It appears that in corners.c a function called susan_corners gets called with a parameter named corner_list. A question is where and how is corner_list declared? I assume it's probably an array of Coordinate structures. Knowing this will tell his how available the data is to other compiled modules.

To back up a bit, do you understand how to compile and link multiple C modules into an project? Do you understand variable scope and linkage? Function parameter passing?

StevenB
01-01-2008, 21:17
tommy_chai: Just so you know, ChiefDelphi isn't primarily for programming questions, so you might get a faster and/or more complete response in a different forum. http://www.chiefdelphi.com/forums/showthread.php?t=29944

If you're using ANSI C, this is typically done using the extern keyword. The other option is to use "getter" functions, like you would in object-oriented programming.
Note that you'll probably want to put the declaration of Coordinate and your functions into a header file, which you can include in both of your c files.
Hope this helps.

tommy_chai
06-01-2008, 03:24
TimCraig: Sorry, it is my mistake, it is declared as:

typedef struct{int x,y,info,dx,dy,I;} CORNER_LIST[15000];
:
:
main(){
CORNER_LIST corner_list;
:
}

I have put the data into a header file which i can reuse it in try5.c However, I am still learning to save the related data into a header file by programming and not manually as i have tried. I don't know how to link multiple C files because i have just started my C programming 1 month ago. Mind showing some codes as example so that it is easier for me to understand and study?

Thanks.

CyDrive
06-01-2008, 11:00
if i understand what your saying and you have properly created a header file for you c files, then all you need to do is add the header file to any file you wish to call the functions in the c file from. Sorry if that sounds confusing. I'm not the best at explaining things.

TimCraig
07-01-2008, 03:02
I don't know how to link multiple C files because i have just started my C programming 1 month ago.


What tools are you using to compile and link your code? I'm curious as to why you're working on such a compliacated problem if you're so inexperienced at C programming? It seems like you need to get through a lot more simple examples before tackling something as complicated as computer vision.



typedef struct
{int x,y,info,dx,dy,I;} CORNER_LIST[15000];



This is pretty ugly and potentially not that useful. I think most people would approach it more along the lines of:


typedef struct
{
int x;
int y;
int info;
int dx;
int dy;
int I;
} CORNER;
.
.
.
CORNER corner_list[15,000];

tommy_chai
11-01-2008, 02:17
Hi all,

First thanks for the corrections. Yup, I have created a header file to keep the data and reused them in try5.c
However, I entered those data into the header file manually since I don't know how to automatically save them from the struct into a header file. The above codes, I got from my supervisor so I am still in progress to understand it. Any idea on the coding to save the data values from struct to a header file?

Thanks for all of the concerns and advices.