38 #ifndef WIN32_LEAN_AND_MEAN 39 #define WIN32_LEAN_AND_MEAN 1 50 #include <sys/types.h> 64 void usage(
const char *programNameP)
67 "USAGE: %s -e <extrinisics_file> -i <intrinsics_file> [<options>]\n",
69 fprintf(stderr,
"Where <options> are:\n");
70 fprintf(stderr,
"\t-a <ip_address> : ip address (default=10.66.171.21)\n");
71 fprintf(stderr,
"\t-s : set the calibration (default is query)\n");
72 fprintf(stderr,
"\t-y : disable confirmation prompts\n");
77 bool fileExists(
const std::string& name)
80 return (0 == stat(name.c_str(), &sbuf));
83 std::ostream& writeImageIntrinics (std::ostream& stream,
image::Calibration const& calibration)
85 stream <<
"%YAML:1.0\n";
93 std::ostream& writeImageExtrinics (std::ostream& stream,
image::Calibration const& calibration)
95 stream <<
"%YAML:1.0\n";
108 std::string ipAddress =
"10.66.171.21";
109 std::string intrinsicsFile;
110 std::string extrinsicsFile;
119 while(-1 != (c =
getopt(argc, argvPP,
"a:e:i:sy")))
121 case 'a': ipAddress = std::string(
optarg);
break;
122 case 'i': intrinsicsFile = std::string(
optarg);
break;
123 case 'e': extrinsicsFile = std::string(
optarg);
break;
124 case 's': setCal =
true;
break;
125 case 'y': prompt =
false;
break;
126 default:
usage(*argvPP);
break;
132 if (intrinsicsFile.empty() || extrinsicsFile.empty()) {
133 fprintf(stderr,
"Both intrinsics and extrinsics files must be set\n");
137 if (
true == setCal &&
138 (
false == fileExists(intrinsicsFile) ||
139 false == fileExists(extrinsicsFile))) {
141 fprintf(stderr,
"intrinsics or extrinsics file not found\n");
145 if (
false == setCal &&
true == prompt &&
146 (
true == fileExists(intrinsicsFile) ||
147 true == fileExists(extrinsicsFile))) {
150 "One or both of \"%s\" and \"%s\" already exists.\n\n" 151 "Really overwrite these files? (y/n): ",
152 intrinsicsFile.c_str(),
153 extrinsicsFile.c_str());
157 if (
'Y' != c &&
'y' != c) {
158 fprintf(stdout,
"Aborting\n");
167 if (NULL == channelP) {
168 fprintf(stderr,
"Failed to establish communications with \"%s\"\n",
181 fprintf(stderr,
"failed to query sensor version: %s\n",
189 if (
false == setCal) {
195 fprintf(stderr,
"failed to query image calibration: %s\n",
200 std::ofstream inFile, exFile;
202 inFile.open (intrinsicsFile.c_str (), std::ios_base::out | std::ios_base::trunc);
205 fprintf(stderr,
"failed to open '%s' for writing\n",
206 intrinsicsFile.c_str());
210 exFile.open (extrinsicsFile.c_str (), std::ios_base::out | std::ios_base::trunc);
213 fprintf(stderr,
"failed to open '%s' for writing\n",
214 extrinsicsFile.c_str());
218 writeImageIntrinics (inFile, c);
219 writeImageExtrinics (exFile, c);
226 std::ifstream inFile, exFile;
227 std::map<std::string, std::vector<float> > data;
229 inFile.open (intrinsicsFile.c_str ());
232 fprintf(stderr,
"failed to open '%s' for reading\n",
233 intrinsicsFile.c_str());
241 if (data[
"M1"].size () != 3 * 3 ||
242 (data[
"D1"].size () != 5 && data[
"D1"].size () != 8) ||
243 data[
"M2"].size () != 3 * 3 ||
244 (data[
"D2"].size () != 5 && data[
"D2"].size () != 8)) {
245 fprintf(stderr,
"intrinsic matrices incomplete in %s\n",
246 intrinsicsFile.c_str());
250 exFile.open (extrinsicsFile.c_str ());
253 fprintf(stderr,
"failed to open '%s' for reading\n",
254 extrinsicsFile.c_str());
262 if (data[
"R1"].size () != 3 * 3 ||
263 data[
"P1"].size () != 3 * 4 ||
264 data[
"R2"].size () != 3 * 3 ||
265 data[
"P2"].size () != 3 * 4) {
266 fprintf(stderr,
"extrinsic matrices incomplete in %s\n",
267 extrinsicsFile.c_str());
273 memcpy (&c.
left.
M[0][0], &data[
"M1"].front (), data[
"M1"].size () *
sizeof (float));
275 memcpy (&c.
left.
D[0], &data[
"D1"].front (), data[
"D1"].size () *
sizeof (float));
276 memcpy (&c.
left.
R[0][0], &data[
"R1"].front (), data[
"R1"].size () *
sizeof (float));
277 memcpy (&c.
left.
P[0][0], &data[
"P1"].front (), data[
"P1"].size () *
sizeof (float));
279 memcpy (&c.
right.
M[0][0], &data[
"M2"].front (), data[
"M2"].size () *
sizeof (float));
281 memcpy (&c.
right.
D[0], &data[
"D2"].front (), data[
"D2"].size () *
sizeof (float));
282 memcpy (&c.
right.
R[0][0], &data[
"R2"].front (), data[
"R2"].size () *
sizeof (float));
283 memcpy (&c.
right.
P[0][0], &data[
"P2"].front (), data[
"P2"].size () *
sizeof (float));
287 fprintf(stderr,
"failed to set image calibration: %s\n",
292 fprintf(stdout,
"Image calibration successfully updated\n");
static const char * statusString(Status status)
static Channel * Create(const std::string &sensorAddress)
std::ostream & writeMatrix(std::ostream &stream, std::string const &name, uint32_t rows, uint32_t columns, T const *data)
int main(int argc, char **argvPP)
int getopt(int argc, char **argv, char *opts)
virtual Status getImageCalibration(image::Calibration &c)=0
static CRL_CONSTEXPR Status Status_Ok
virtual Status setImageCalibration(const image::Calibration &c)=0
std::istream & parseYaml(std::istream &stream, std::map< std::string, std::vector< float > > &data)
static void Destroy(Channel *instanceP)
virtual Status getSensorVersion(VersionType &version)=0