ChangeResolution.cc
Go to the documentation of this file.
1 
36 #ifdef WIN32
37 #ifndef WIN32_LEAN_AND_MEAN
38 #define WIN32_LEAN_AND_MEAN 1
39 #endif
40 
41 #include <windows.h>
42 #include <winsock2.h>
43 #else
44 #include <unistd.h>
45 #include <netdb.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
49 #endif
50 
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string>
54 #include <fstream>
55 #include <iostream>
56 #include <iomanip>
57 
58 #include <errno.h>
59 #include <string.h>
60 
63 
67 
69 
70 namespace { // anonymous
71 
72 void usage(const char *programNameP)
73 {
74  fprintf(stderr, "USAGE: %s [<options>]\n", programNameP);
75  fprintf(stderr, "Where <options> are:\n");
76  fprintf(stderr, "\t-a address : MultiSense IP Address (default=10.66.171.21)\n");
77  fprintf(stderr, "\t-h height : Imager width, in px (default=544)\n");
78  fprintf(stderr, "\t-w width : Imager height, in px (default=1024)\n");
79  fprintf(stderr, "\t-m mode : Imager crop mode, (default=0)\n");
80  fprintf(stderr, "\t 0 = No change sent\n");
81  fprintf(stderr, "\t 2000 = Switch to CMV2000 ROI\n");
82  fprintf(stderr, "\t 4000 = Switch to CMV4000 ROI\n");
83  fprintf(stderr, "\t-o offset : Position of cropped ROI, in px from bottom of image\n");
84  fprintf(stderr, "\t -1 = No change sent\n");
85  fprintf(stderr, "\t 0 = ROI is bottom of CMV4000 FOV\n");
86  fprintf(stderr, "\t 480 = ROI is center of CMV4000 FOV, assuming full resolution\n");
87  fprintf(stderr, "\t 960 = ROI is top of CMV4000 FOV, assuming full resolution\n");
88 
89  exit(-1);
90 }
91 
92 }; // anonymous
93 
94 using namespace crl::multisense;
95 
96 int main(int argc,
97  char **argvPP)
98 {
99  std::string currentAddress = "10.66.171.21";
100  int32_t height = 544;
101  uint32_t width = 1024;
102  int mode = 0;
103  int offset = -1;
104 
105  //
106  // Parse args
107 
108  int c;
109 
110  while(-1 != (c = getopt(argc, argvPP, "a:h:w:m:o:")))
111  switch(c) {
112  case 'a': currentAddress = std::string(optarg); break;
113  case 'h': height = atoi(optarg); break;
114  case 'w': width = atoi(optarg); break;
115  case 'm': mode = atoi(optarg); break;
116  case 'o': offset = atoi(optarg); break;
117  default: usage(*argvPP); break;
118  }
119 
120  //
121  // Initialize communications.
122 
123  Channel *channelP = Channel::Create(currentAddress);
124  if (NULL == channelP) {
125  std::cerr << "Failed to establish communications with \"" << currentAddress << "\"" << std::endl;
126  return -1;
127  }
128 
129  //
130  // Query version
131 
132  Status status;
134 
135  status = channelP->getVersionInfo(v);
136  if (Status_Ok != status) {
137  std::cerr << "Failed to query sensor version: " << Channel::statusString(status) << std::endl;
138  goto clean_out;
139  }
140 
141  std::cout << "API build date : " << v.apiBuildDate << "\n";
142  std::cout << "API version : 0x" << std::hex << std::setw(4) << std::setfill('0') << v.apiVersion << "\n";
143  std::cout << "Firmware build date : " << v.sensorFirmwareBuildDate << "\n";
144  std::cout << "Firmware version : 0x" << std::hex << std::setw(4) << std::setfill('0') << v.sensorFirmwareVersion << "\n";
145  std::cout << "Hardware version : 0x" << std::hex << v.sensorHardwareVersion << "\n";
146  std::cout << "Hardware magic : 0x" << std::hex << v.sensorHardwareMagic << "\n";
147  std::cout << "FPGA DNA : 0x" << std::hex << v.sensorFpgaDna << "\n";
148  std::cout << std::dec;
149 
150  if (v.sensorFirmwareVersion < 0x0305) {
151  if (mode != 0 || offset >= 0) {
152  std::cerr << "Changing crop mode of a CMV4000 imager requires v3.5 or greater, sensor is " <<
153  "running v" << (v.sensorFirmwareVersion >> 8) << "." << (v.sensorFirmwareVersion & 0xff) << std::endl;
154  goto clean_out;
155  }
156  }
157 
158  //
159  // Change operating parameters
160 
161  {
162  image::Config cfg;
163 
164  status = channelP->getImageConfig(cfg);
165  if (Status_Ok != status) {
166  std::cerr << "Failed to get image config: " << Channel::statusString(status) << std::endl;
167  goto clean_out;
168  } else {
169  if (mode != 0) {
170  cfg.setCamMode(mode);
171  }
172 
173  cfg.setResolution(width, height);
174 
175  if (offset >= 0) {
176  cfg.setOffset(offset);
177  }
178 
179  status = channelP->setImageConfig(cfg);
180  if (Status_Ok != status) {
181  std::cerr << "Failed to configure sensor: " << Channel::statusString(status) << std::endl;
182  goto clean_out;
183  }
184  }
185  }
186 
187 clean_out:
188 
189  Channel::Destroy(channelP);
190  return 0;
191 }
void setResolution(uint32_t w, uint32_t h)
virtual Status getVersionInfo(system::VersionInfo &v)=0
int getopt(int argc, char **argv, char *opts)
Definition: getopt.c:34
int main(int argc, char **argvPP)
static CRL_CONSTEXPR Status Status_Ok
virtual Status setImageConfig(const image::Config &c)=0
def usage(progname)
char * optarg
Definition: getopt.c:32
virtual Status getImageConfig(image::Config &c)=0


multisense_lib
Author(s):
autogenerated on Sat Apr 6 2019 02:16:46