00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "calibration_standalone.h"
00034
00035
00037
00038 void
00039 setInitialIntrinsicParameters (std::vector<SensorDataEntry> &inputData)
00040 {
00041 SensorDataEntry s;
00042 s.sensor = "stoc";
00043 s.camera = "left";
00044 std::vector<SensorDataEntry>::iterator it = find (inputData.begin (), inputData.end (), s);
00045 if (it != inputData.end ())
00046 {
00047 SensorDataEntry *pen = &(*it);
00048 cvmSet (pen->intrinsic, 0, 0, 1338.77747); cvmSet (pen->intrinsic, 0, 1, 0.0); cvmSet (pen->intrinsic, 0, 2, 552.81012);
00049 cvmSet (pen->intrinsic, 1, 0, 0.0); cvmSet (pen->intrinsic, 1, 1, 1338.77747); cvmSet (pen->intrinsic, 1, 2, 374.58749);
00050 cvmSet (pen->intrinsic, 2, 0, 0.0); cvmSet (pen->intrinsic, 2, 1, 0.0); cvmSet (pen->intrinsic, 2, 2, 1.0);
00051 cvmSet (pen->distortion, 0, 0, 0.04920); cvmSet (pen->distortion, 0, 1, -0.20187); cvmSet (pen->distortion, 0, 2, 0.0); cvmSet (pen->distortion, 0, 3, 0.0);
00052 }
00053
00054 s.sensor = "stoc";
00055 s.camera = "right";
00056 it = find (inputData.begin (), inputData.end (), s);
00057 if (it != inputData.end ())
00058 {
00059 SensorDataEntry *pen = &(*it);
00060 cvmSet (pen->intrinsic, 0, 0, 1339.43933); cvmSet (pen->intrinsic, 0, 1, 0.0); cvmSet (pen->intrinsic, 0, 2, 503.67599);
00061 cvmSet (pen->intrinsic, 1, 0, 0.0); cvmSet (pen->intrinsic, 1, 1, 1339.43933); cvmSet (pen->intrinsic, 1, 2, 394.59033);
00062 cvmSet (pen->intrinsic, 2, 0, 0.0); cvmSet (pen->intrinsic, 2, 1, 0.0); cvmSet (pen->intrinsic, 2, 2, 1.0);
00063 cvmSet (pen->distortion, 0, 0, -0.00809); cvmSet (pen->distortion, 0, 1, -0.09067); cvmSet (pen->distortion, 0, 2, 0.0); cvmSet (pen->distortion, 0, 3, 0.0);
00064 }
00065 }
00066
00067
00068 int
00069 main (int argc, char** argv)
00070 {
00071 std::vector<int> badPairs;
00072
00073 double max_admissible_err = FLT_MAX;
00074 if (argc < 2)
00075 {
00076 fprintf (stderr, "Syntax is: %s <file1..N.{jpg,png}*> <options>\n", argv[0]);
00077 fprintf (stderr, " where options are:\n");
00078 fprintf (stderr, " -squares X,Y = use these numbers of squares to define the checkboard pattern\n");
00079 fprintf (stderr, " -sq_size X = square size in mm\n");
00080 fprintf (stderr, "\n");
00081 fprintf (stderr, " -ith X = get only every Xth pair (useful if we have over 100 pairs of recorded images)\n");
00082 fprintf (stderr, "\n");
00083 fprintf (stderr, " -max_err X = ignore a pair if the pixel reprojection error is larger than X (default: MAX_FLT)\n");
00084 fprintf (stderr, "\n");
00085 fprintf (stderr, " -wait X = how much time to wait between each image (default : 0 - wait for a keypress)\n");
00086 fprintf (stderr, "\n");
00087 fprintf (stderr, "* note: the number of files will be parsed as folows: NR-SID-CID.png, where:\n");
00088 fprintf (stderr, " - NR = the actual image pair number\n");
00089 fprintf (stderr, " - SID = a string identifier which defines the sensor used (e.g. stoc, sr4k, etc)\n");
00090 fprintf (stderr, " - CID = a string identifier which defines the camera used (e.g. left, right, intensity, etc)\n");
00091 return (-1);
00092 }
00093
00094
00095 int wait = 0;
00096 ParseArgument (argc, argv, "-wait", wait);
00097
00098 ParseArgument (argc, argv, "-max_err", max_admissible_err);
00099
00100 int sq_size = SQ_SIZE;
00101 ParseArgument (argc, argv, "-sq_size", sq_size);
00102
00103 int ith = 1;
00104 ParseArgument (argc, argv, "-ith", ith);
00105
00106
00107 int nr_sqr_x = NR_SQUARE_X,
00108 nr_sqr_y = NR_SQUARE_Y;
00109 ParseRangeArguments (argc, argv, "-squares", nr_sqr_x, nr_sqr_y);
00110 CvSize checkboard = cvSize (nr_sqr_x, nr_sqr_y);
00111
00112 fprintf (stderr, "Using %d, %d with %d checkboard.\n", nr_sqr_x, nr_sqr_y, sq_size);
00113
00114
00115 std::vector<int> pPNGFileIndices;
00116 pPNGFileIndices = ParseFileExtensionArgument (argc, argv, ".png");
00117
00118 if (pPNGFileIndices.size () == 0)
00119 pPNGFileIndices = ParseFileExtensionArgument (argc, argv, ".jpg");
00120
00121 std::vector<SensorDataEntry> inputData = createSensorEntries (argc, argv, pPNGFileIndices, checkboard, ith);
00122
00123 fprintf (stderr, "Maximum admissible pixel reprojection error for an image: "); fprintf (stderr, "%g\n", max_admissible_err);
00124
00125 setInitialIntrinsicParameters (inputData);
00126
00127
00128 int nr_valid_pairs = 0;
00129 for (unsigned int i = 0; i < inputData.size (); i++)
00130 {
00131 SensorDataEntry *s = &inputData.at (i);
00132 nr_valid_pairs = computeIntrinsicParameters (inputData.at (i), checkboard, sq_size, badPairs,
00133 max_admissible_err, wait);
00134 if (nr_valid_pairs == -1)
00135 return (-1);
00136
00137 computeExtrinsicParameters (inputData.at (i), checkboard, nr_valid_pairs);
00138
00139 fprintf (stderr, " >>> INTRINSIC PARAMETERS for "); fprintf (stderr, "%s-%s\n", s->sensor.c_str (), s->camera.c_str ());
00140 printMatrix (s->intrinsic);
00141 fprintf (stderr, " Camera Distortion Coefficients\n");
00142 printMatrix (s->distortion);
00143 }
00144
00145
00146 int nr_pairs = nr_valid_pairs;
00147 int nums[nr_pairs];
00148 for (int i = 0; i < nr_pairs; i++)
00149 nums[i] = checkboard.height * checkboard.width;
00150
00151 getExtrinsicBetween ("stoc-left", "stoc-right", checkboard, inputData, nr_pairs, nums);
00152 getExtrinsicBetween ("stoc-right", "stoc-left", checkboard, inputData, nr_pairs, nums);
00153
00154 finishUp (inputData);
00155 return (0);
00156 }