RectifiedFocalLengthUtility.cc
Go to the documentation of this file.
1 
37 #ifdef WIN32
38 #ifndef WIN32_LEAN_AND_MEAN
39 #define WIN32_LEAN_AND_MEAN 1
40 #endif
41 
42 #include <windows.h>
43 #include <winsock2.h>
44 #else
45 #include <unistd.h>
46 #endif
47 
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <sys/types.h>
51 #include <sys/stat.h>
52 #include <fstream>
53 #include <map>
54 #include <string.h>
55 
60 
61 using namespace crl::multisense;
62 
63 namespace { // anonymous
64 
65 void usage(const char *programNameP)
66 {
67  fprintf(stderr,
68  "USAGE: %s -f <rectified_focal_length> [<options>]\n",
69  programNameP);
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 rectified focal length (default is query)\n");
73 
74  exit(-1);
75 }
76 
77 
78 } // anonymous
79 
80 int main(int argc,
81  char **argvPP)
82 {
83  std::string ipAddress = "10.66.171.21";
84  double rectifiedFocalLength = -1.0;
85  bool set = false;
86  bool hasAuxCamera = false;
87  double currentFocalLength = 0.0;
88  double tx = 0.0;
89  double auxTx = 0.0;
90  double auxTy = 0.0;
91 
92  //
93  // Parse args
94 
95  int c;
96 
97  while(-1 != (c = getopt(argc, argvPP, "a:f:s")))
98  switch(c) {
99  case 'a': ipAddress = std::string(optarg); break;
100  case 'f': rectifiedFocalLength = atof(optarg); break;
101  case 's': set = true; break;
102  default: usage(*argvPP); break;
103  }
104 
105  //
106  // Verify options. New focal lengths should be positive and large enough for the onboard
107  // stereo pipeline
108 
109  if (rectifiedFocalLength < 200.0) {
110  fprintf(stderr, "Invalid rectified focal length\n");
111  usage(*argvPP);
112  }
113 
114  //
115  // Initialize communications.
116 
117  Channel *channelP = Channel::Create(ipAddress);
118  if (NULL == channelP) {
119  fprintf(stderr, "Failed to establish communications with \"%s\"\n",
120  ipAddress.c_str());
121  return -1;
122  }
123 
124  //
125  // Query Device Info
126 
127  Status status;
128 
129  system::DeviceInfo info;
130  status = channelP->getDeviceInfo(info);
131  if (Status_Ok != status)
132  {
133  fprintf(stderr, "Failed to query device info: %s\n",
134  Channel::statusString(status));
135  goto clean_out;
136  }
137 
141 
142  image::Calibration calibration;
143 
144  status = channelP->getImageCalibration(calibration);
145  if (Status_Ok != status) {
146  fprintf(stderr, "failed to query image calibration: %s\n",
147  Channel::statusString(status));
148  goto clean_out;
149  }
150 
151  currentFocalLength = calibration.left.P[0][0];
152  fprintf(stdout, "updating focal length from %f to %f\n",
153  currentFocalLength, rectifiedFocalLength);
154 
155  if (set) {
156 
157  tx = calibration.right.P[0][3] / calibration.right.P[0][0];
158 
159  calibration.left.P[0][0] = static_cast<float> (rectifiedFocalLength);
160  calibration.left.P[1][1] = static_cast<float> (rectifiedFocalLength);
161  calibration.right.P[0][0] = static_cast<float> (rectifiedFocalLength);
162  calibration.right.P[1][1] = static_cast<float> (rectifiedFocalLength);
163  calibration.right.P[0][3] = static_cast<float> (rectifiedFocalLength * tx);
164 
165  if (hasAuxCamera) {
166 
167  auxTx = calibration.aux.P[0][3] / calibration.aux.P[0][0];
168  auxTy = calibration.aux.P[1][3] / calibration.aux.P[1][1];
169 
170  calibration.aux.P[0][0] = static_cast<float> (rectifiedFocalLength);
171  calibration.aux.P[1][1] = static_cast<float> (rectifiedFocalLength);
172  calibration.aux.P[0][3] = static_cast<float> (rectifiedFocalLength * auxTx);
173  calibration.aux.P[1][3] = static_cast<float> (rectifiedFocalLength * auxTy);
174  }
175 
176  status = channelP->setImageCalibration(calibration);
177  if (Status_Ok != status) {
178  fprintf(stderr, "failed to set image calibration: %s\n",
179  Channel::statusString(status));
180  goto clean_out;
181  }
182 
183  fprintf(stdout, "Rectified focal length successfully updated to %f\n",
184  rectifiedFocalLength);
185  } else {
186 
187  fprintf(stdout, "Please specify -s to update the rectified focal length to %f\n",
188  rectifiedFocalLength);
189  }
190 
191 clean_out:
192 
193  Channel::Destroy(channelP);
194  return 0;
195 }
static const char * statusString(Status status)
Definition: channel.cc:802
static Channel * Create(const std::string &sensorAddress)
Definition: channel.cc:743
int getopt(int argc, char **argv, char *opts)
Definition: getopt.c:31
virtual Status getImageCalibration(image::Calibration &c)=0
static CRL_CONSTEXPR uint32_t HARDWARE_REV_MULTISENSE_MONOCAM
static CRL_CONSTEXPR Status Status_Ok
int main(int argc, char **argvPP)
static CRL_CONSTEXPR uint32_t HARDWARE_REV_MULTISENSE_S30
virtual Status setImageCalibration(const image::Calibration &c)=0
def usage(progname)
static CRL_CONSTEXPR uint32_t HARDWARE_REV_MULTISENSE_C6S2_S27
virtual Status getDeviceInfo(system::DeviceInfo &info)=0
static void Destroy(Channel *instanceP)
Definition: channel.cc:789
char * optarg
Definition: getopt.c:29


multisense_lib
Author(s):
autogenerated on Sat Jun 24 2023 03:01:21