Skip to content

Commit

Permalink
Locations of markers are now output to the output.csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Grijalva committed Jun 3, 2014
1 parent 6af3a2b commit ec7f480
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
21 changes: 13 additions & 8 deletions AR_Simple/FileWriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@ void createOutputFile()
FILE* file = fopen("output.csv", "w"); // This will delete any existing file
if (file != NULL)
{
fputs("image,x,y\n", file);
fputs("image,center_x,center_y,A_x,A_y,B_x,B_y,D_x,D_y,G_x,G_y\n", file);
fclose(file);
}
}

void writeLine(char* img_name, int x, int y)
void writeLine(char* img_name, int x, int y,
int ax, int ay,
int bx, int by,
int dx, int dy,
int gx, int gy)
{
FILE* file = fopen("output.csv", "a");
char* line = calloc(strlen(img_name) + 8 + 3, sizeof(char));
char* line = calloc(strlen(img_name) + 40 + 3, sizeof(char));

strcpy(line, img_name);
strcat(line, ",");
char buffer[10];
sprintf(buffer, "%d", x);
strcat(line, buffer);
strcat(line, ",");
sprintf(buffer, "%d", y);
char buffer[256];
sprintf(buffer, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", x, y,
ax, ay,
bx, by,
dx, dy,
gx, gy);
strcat(line, buffer);
strcat(line, "\n");

Expand Down
10 changes: 9 additions & 1 deletion AR_Simple/FileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ void createOutputFile();
img_name: name of the image file
x: x position of the sphere for this image
y: y position of the sphere for this image
ax & ay: Location of marker A
bx & by: Location of marker B
dx & dy: Location of marker D
gx & gy: Location of marker G
*/
void writeLine(char* img_name, int x, int y);
void writeLine(char* img_name, int x, int y,
int ax, int ay,
int bx, int by,
int dx, int dy,
int gx, int gy);

#endif
18 changes: 15 additions & 3 deletions AR_Simple/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void calculateAverage(int num)
}
rx /= num; ry /= num;
printf("Average location: %i, %i\n", rx, ry);
writeLine("Average", rx, ry);
writeLine("Average", rx, ry, 0,0,0,0,0,0,0,0);
}

/*
Expand All @@ -165,6 +165,8 @@ static void mainLoop(char* img_name)
printf("%d potential markers found\n", marker_num);
printf("The following patterns have been identified: ");
int pattern_count = 0;
int marker_loc[8]; // For saving x,y positions of each marker
for (int i = 0; i < 8; i++) marker_loc[i] = 0;

for (int i = 0; i < marker_num; i++)
{
Expand All @@ -175,6 +177,8 @@ static void mainLoop(char* img_name)
{
if (marker_info[i].id == object[j].id)
{
marker_loc[marker_info[i].id * 2] = marker_info[i].pos[0]; // Save x position
marker_loc[marker_info[i].id * 2 + 1] = marker_info[i].pos[1]; // Save y position
printf("%s ", object[j].name);
break;
}
Expand All @@ -191,14 +195,22 @@ static void mainLoop(char* img_name)
get_pair(&pair, marker_info, marker_num, pattern_count);
get_midpoint(&midpoint, &pair);
printf("Center is: %5i,%5i\n", (int)midpoint[0], (int)midpoint[1]);
writeLine(img_name, (int)midpoint[0], (int)midpoint[1]);
writeLine(img_name, (int)midpoint[0], (int)midpoint[1],
marker_loc[0], marker_loc[1],
marker_loc[2], marker_loc[3],
marker_loc[4], marker_loc[5],
marker_loc[6], marker_loc[7]);
centers[img_num][0] = (int)midpoint[0]; // Save the x position
centers[img_num++][1] = (int)midpoint[1]; // Save the y position
}
else
{
printf("%i patterns isnt enough to find a center point!\n", marker_num);
writeLine(img_name, 0, 0);
writeLine(img_name, 0, 0,
marker_loc[0], marker_loc[1],
marker_loc[2], marker_loc[3],
marker_loc[4], marker_loc[5],
marker_loc[6], marker_loc[7]);
centers[img_num][0] = 0; // Save the x position
centers[img_num++][1] = 0; // Save the y position
}
Expand Down

0 comments on commit ec7f480

Please sign in to comment.