38 #ifndef WIN32_LEAN_AND_MEAN 39 #define WIN32_LEAN_AND_MEAN 1 50 #include <sys/types.h> 65 void usage(
const char *programNameP)
68 "USAGE: %s -e <extrinisics_file> -i <intrinsics_file> [<options>]\n",
70 fprintf(stderr,
"Where <options> are:\n");
71 fprintf(stderr,
"\t-a <ip_address> : ip address (default=10.66.171.21)\n");
72 fprintf(stderr,
"\t-s : set the calibration (default is query)\n");
73 fprintf(stderr,
"\t-y : disable confirmation prompts\n");
78 bool fileExists(
const std::string& name)
81 return (0 == stat(name.c_str(), &sbuf));
84 std::ostream& writeImageIntrinics (std::ostream& stream,
image::Calibration const& calibration,
bool hasAuxCamera)
86 stream <<
"%YAML:1.0\n";
100 std::ostream& writeImageExtrinics (std::ostream& stream,
image::Calibration const& calibration,
bool hasAuxCamera)
102 stream <<
"%YAML:1.0\n";
121 std::string ipAddress =
"10.66.171.21";
122 std::string intrinsicsFile;
123 std::string extrinsicsFile;
132 while(-1 != (c =
getopt(argc, argvPP,
"a:e:i:sy")))
134 case 'a': ipAddress = std::string(
optarg);
break;
135 case 'i': intrinsicsFile = std::string(
optarg);
break;
136 case 'e': extrinsicsFile = std::string(
optarg);
break;
137 case 's': setCal =
true;
break;
138 case 'y': prompt =
false;
break;
139 default:
usage(*argvPP);
break;
145 if (intrinsicsFile.empty() || extrinsicsFile.empty()) {
146 fprintf(stderr,
"Both intrinsics and extrinsics files must be set\n");
150 if (
true == setCal &&
151 (
false == fileExists(intrinsicsFile) ||
152 false == fileExists(extrinsicsFile))) {
154 fprintf(stderr,
"intrinsics or extrinsics file not found\n");
158 if (
false == setCal &&
true == prompt &&
159 (
true == fileExists(intrinsicsFile) ||
160 true == fileExists(extrinsicsFile))) {
163 "One or both of \"%s\" and \"%s\" already exists.\n\n" 164 "Really overwrite these files? (y/n): ",
165 intrinsicsFile.c_str(),
166 extrinsicsFile.c_str());
169 int reply = getchar();
170 if (
'Y' != reply &&
'y' != reply) {
171 fprintf(stdout,
"Aborting\n");
180 if (NULL == channelP) {
181 fprintf(stderr,
"Failed to establish communications with \"%s\"\n",
192 bool hasAuxCamera =
false;
196 fprintf(stderr,
"Failed to query device info: %s\n",
207 if (
false == setCal) {
213 fprintf(stderr,
"failed to query image calibration: %s\n",
218 std::ofstream inFile, exFile;
220 inFile.open (intrinsicsFile.c_str (), std::ios_base::out | std::ios_base::trunc);
223 fprintf(stderr,
"failed to open '%s' for writing\n",
224 intrinsicsFile.c_str());
228 exFile.open (extrinsicsFile.c_str (), std::ios_base::out | std::ios_base::trunc);
231 fprintf(stderr,
"failed to open '%s' for writing\n",
232 extrinsicsFile.c_str());
236 writeImageIntrinics (inFile, calibration, hasAuxCamera);
237 writeImageExtrinics (exFile, calibration, hasAuxCamera);
244 std::ifstream inFile, exFile;
245 std::map<std::string, std::vector<float> > data;
247 inFile.open (intrinsicsFile.c_str ());
250 fprintf(stderr,
"failed to open '%s' for reading\n",
251 intrinsicsFile.c_str());
259 if (data[
"M1"].size () != 3 * 3 ||
260 (data[
"D1"].size () != 5 && data[
"D1"].size () != 8) ||
261 data[
"M2"].size () != 3 * 3 ||
262 (data[
"D2"].size () != 5 && data[
"D2"].size () != 8) ||
263 (hasAuxCamera && data[
"M3"].size () != 3 * 3) ||
264 (hasAuxCamera && data[
"D3"].size () != 5 && data[
"D3"].size () != 8)) {
265 fprintf(stderr,
"intrinsic matrices incomplete in %s\n",
266 intrinsicsFile.c_str());
270 exFile.open (extrinsicsFile.c_str ());
273 fprintf(stderr,
"failed to open '%s' for reading\n",
274 extrinsicsFile.c_str());
282 if (data[
"R1"].size () != 3 * 3 ||
283 data[
"P1"].size () != 3 * 4 ||
284 data[
"R2"].size () != 3 * 3 ||
285 data[
"P2"].size () != 3 * 4 ||
286 (hasAuxCamera && (data[
"R3"].size () != 3 * 3 || data[
"P3"].size () != 3 * 4))) {
287 fprintf(stderr,
"extrinsic matrices incomplete in %s\n",
288 extrinsicsFile.c_str());
294 memcpy (&calibration.
left.
M[0][0], &data[
"M1"].front (), data[
"M1"].size () *
sizeof (float));
295 memset (&calibration.
left.
D[0], 0, sizeof (calibration.
left.
D));
296 memcpy (&calibration.
left.
D[0], &data[
"D1"].front (), data[
"D1"].size () *
sizeof (float));
297 memcpy (&calibration.
left.
R[0][0], &data[
"R1"].front (), data[
"R1"].size () *
sizeof (float));
298 memcpy (&calibration.
left.
P[0][0], &data[
"P1"].front (), data[
"P1"].size () *
sizeof (float));
300 memcpy (&calibration.
right.
M[0][0], &data[
"M2"].front (), data[
"M2"].size () *
sizeof (float));
301 memset (&calibration.
right.
D[0], 0, sizeof (calibration.
right.
D));
302 memcpy (&calibration.
right.
D[0], &data[
"D2"].front (), data[
"D2"].size () *
sizeof (float));
303 memcpy (&calibration.
right.
R[0][0], &data[
"R2"].front (), data[
"R2"].size () *
sizeof (float));
304 memcpy (&calibration.
right.
P[0][0], &data[
"P2"].front (), data[
"P2"].size () *
sizeof (float));
308 memcpy (&calibration.
aux.
M[0][0], &data[
"M3"].front (), data[
"M3"].size () *
sizeof (float));
309 memset (&calibration.
aux.
D[0], 0, sizeof (calibration.
aux.
D));
310 memcpy (&calibration.
aux.
D[0], &data[
"D3"].front (), data[
"D3"].size () *
sizeof (float));
311 memcpy (&calibration.
aux.
R[0][0], &data[
"R3"].front (), data[
"R3"].size () *
sizeof (float));
312 memcpy (&calibration.
aux.
P[0][0], &data[
"P3"].front (), data[
"P3"].size () *
sizeof (float));
317 fprintf(stderr,
"failed to set image calibration: %s\n",
322 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
uint32_t hardwareRevision
static CRL_CONSTEXPR Status Status_Ok
static CRL_CONSTEXPR uint32_t HARDWARE_REV_MULTISENSE_S30
virtual Status setImageCalibration(const image::Calibration &c)=0
std::istream & parseYaml(std::istream &stream, std::map< std::string, std::vector< float > > &data)
static CRL_CONSTEXPR uint32_t HARDWARE_REV_MULTISENSE_C6S2_S27
virtual Status getDeviceInfo(system::DeviceInfo &info)=0
static void Destroy(Channel *instanceP)