1 /*******************************************************************************\
2 * *
3 * This program allows a user to interactively convert 3D world coordinates *
4 * into 2D image coordinates. The perform the conversion the program requires *
5 * a calibrated camera model of the form generated by ccal, ccal_fo, ncal, *
6 * or ncal_fo. *
7 * *
8 * History *
9 * ------- *
10 * *
11 * 01-Apr-95 Reg Willson (rgwillson@mmm.com) at 3M St. Paul, MN *
12 * Filename changes for DOS port. *
13 * *
14 * 30-May-93 Reg Willson (rgw@cs.cmu.edu) at Carnegie-Mellon University *
15 * Original implementation. *
16 * *
17 \*******************************************************************************/
18
19 #include <stdio.h>
20 #include <math.h>
21 #include "cal_main.h"
22
main(argc,argv)23 main (argc, argv)
24 int argc;
25 char **argv;
26 {
27 FILE *data_fd;
28
29 double Xw,
30 Yw,
31 Zw,
32 Xfd,
33 Yfd,
34 atof ();
35
36 char temp[256];
37
38 if (argc != 2) {
39 (void) fprintf (stderr, "syntax: %s datafile\n", argv[0]);
40 exit (-1);
41 }
42 /* load up the camera parameters and calibration constants from the given data file */
43 if ((data_fd = fopen (argv[1], "r")) == NULL) {
44 (void) fprintf (stderr, "%s: unable to open file \"%s\"\n", argv[0], argv[1]);
45 exit (-1);
46 }
47
48 load_cp_cc_data (data_fd, &cp, &cc);
49 fclose (data_fd);
50
51 (void) fprintf (stdout, "\n Input file: %s\n\n", argv[1]);
52
53 print_cp_cc_data (stdout, &cp, &cc);
54
55 while (1) {
56 /* prompt for the world coordinates */
57 (void) fprintf (stdout, "\n Enter Xw [mm] : ");
58 if (gets (temp) == NULL)
59 break;
60 Xw = atof (temp);
61
62 (void) fprintf (stdout, "\n Enter Yw [mm] : ");
63 if (gets (temp) == NULL)
64 break;
65 Yw = atof (temp);
66
67 (void) fprintf (stdout, "\n Enter Zw [mm] : ");
68 if (gets (temp) == NULL)
69 break;
70 Zw = atof (temp);
71
72 /* determine the corresponding image coordinates */
73 world_coord_to_image_coord (Xw, Yw, Zw, &Xfd, &Yfd);
74
75 (void) fprintf (stdout,
76 "\n [Xw,Yw,Zw] = [%.2lf, %.2lf, %.2lf] --> [Xf,Yf] = [%.2lf, %.2lf]\n",
77 Xw, Yw, Zw, Xfd, Yfd);
78 }
79
80 (void) fprintf (stdout, "\n\n");
81
82 return 0;
83 }
84