diff --git a/AR_Simple/FileWriter.c b/AR_Simple/FileWriter.c index ae2f4ee..f3114e8 100644 --- a/AR_Simple/FileWriter.c +++ b/AR_Simple/FileWriter.c @@ -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"); diff --git a/AR_Simple/FileWriter.h b/AR_Simple/FileWriter.h index a6c7c2c..2d0268c 100644 --- a/AR_Simple/FileWriter.h +++ b/AR_Simple/FileWriter.h @@ -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 diff --git a/AR_Simple/Main.c b/AR_Simple/Main.c index 6561bd7..7073be3 100644 --- a/AR_Simple/Main.c +++ b/AR_Simple/Main.c @@ -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); } /* @@ -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++) { @@ -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; } @@ -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 }