42 <<
"Usage: " << program <<
" [OPTIONS] IMAGE [10 shot integers]\n"
43 <<
" --local Development-PC mode; no hardware or remote "
45 <<
" --aicam Select the AI camera handler.\n"
46 <<
" --chdkcam Select the CHDK camera handler.\n"
47 <<
" --lwircam Select the thermal camera handler.\n"
48 <<
" --earcam Select the acoustic camera handler.\n"
49 <<
" --lens-profile FILE Emulate a lens before AIcam analysis "
50 "(requires --local --aicam).\n"
51 <<
" --lens-cache DIR Optional zoom-18 XYZ cache (pprzgcs legacy path GOOGLE/18) "
53 <<
" --version Show application name, version, and build Git "
55 <<
" --help Show this help.\n"
56 <<
" -- End option parsing.\n"
57 <<
"Select at most one camera; otherwise use the generic handler.\n"
58 <<
"IMAGE must be readable and nonempty. Optional int32 shot values:\n"
59 <<
"number latitude longitude altitude roll pitch yaw speed course "
64 std::cout <<
"Now I can do nifty stuff for aicam" << std::endl;
67void process_chdkcam() {
68 std::cout <<
"Now I can do nifty stuff for chdkcam" << std::endl;
71void process_lwircam() {
72 std::cout <<
"Now I can do nifty stuff for lwircam" << std::endl;
75void process_earcam() {
76 std::cout <<
"Now I can do nifty stuff for earcam" << std::endl;
84const CameraHandler handlers[] = {{
"--aicam", process_aicam},
85 {
"--chdkcam", process_chdkcam},
86 {
"--lwircam", process_lwircam},
87 {
"--earcam", process_earcam}};
89bool is_shot_value(
const char* text) {
90 const char* digit = text;
91 if (*digit ==
'-' || *digit ==
'+') ++digit;
92 if (*digit ==
'\0')
return false;
93 for (; *digit !=
'\0'; ++digit) {
94 if (*digit <
'0' || *digit >
'9')
return false;
98 const long long value = std::strtoll(text, &end, 10);
99 return errno != ERANGE && *end ==
'\0' &&
100 value >= std::numeric_limits<int32_t>::min() &&
101 value <= std::numeric_limits<int32_t>::max();
104bool emulate_lens(
const char* input,
const char*
profile,
const char* cache,
106 char executable[4096];
108 readlink(
"/proc/self/exe", executable,
sizeof(executable) - 1);
109 if (length <= 0 ||
static_cast<size_t>(length) >=
sizeof(executable) - 1)
111 executable[length] =
'\0';
112 std::string directory(executable);
113 directory.resize(directory.find_last_of(
'/'));
114 const std::string executable_path = directory +
"/camera_lens";
115 if (access(executable_path.c_str(), X_OK) != 0) {
116 std::cerr <<
"SODA: native lens executable missing; run make camera-lens "
117 "in the USHER directory\n";
120 char derivative[4096];
122 derivative,
sizeof(derivative),
nullptr))
135int main(
int argc,
char* argv[]) {
136 const CameraHandler* selected =
nullptr;
137 const char* lens_profile =
nullptr;
138 const char* lens_cache =
nullptr;
139 std::vector<const char*> positional;
143 bool version =
false;
144 for (
int argument = 1; argument < argc; ++argument) {
145 const char* value = argv[argument];
146 if (
options && (std::strcmp(value,
"--lens-profile") == 0 ||
147 std::strcmp(value,
"--lens-cache") == 0)) {
148 const char** destination = std::strcmp(value,
"--lens-profile") == 0
151 if (*destination !=
nullptr || argument + 1 >= argc ||
152 argv[argument + 1][0] ==
'\0') {
153 std::cerr <<
"SODA: missing or duplicate lens option\n";
156 *destination = argv[++argument];
159 if (
options && std::strcmp(value,
"--") == 0) {
163 if (
options && std::strcmp(value,
"--local") == 0) {
165 std::cerr <<
"SODA: duplicate --local option" << std::endl;
171 if (
options && std::strcmp(value,
"--help") == 0) {
175 if (
options && std::strcmp(value,
"--version") == 0) {
179 const CameraHandler* match =
nullptr;
181 for (
const CameraHandler& handler : handlers) {
182 if (std::strcmp(value, handler.option) == 0) match = &handler;
185 if (match !=
nullptr) {
186 if (selected !=
nullptr) {
187 std::cerr <<
"SODA: specify only one camera selector" << std::endl;
191 }
else if (
options && value[0] ==
'-' && !is_shot_value(value)) {
192 std::cerr <<
"SODA: unknown option " << value << std::endl;
195 positional.push_back(value);
206 if (positional.empty()) {
207 std::cerr <<
"SODA: no image was provided" << std::endl;
210 if ((lens_cache !=
nullptr && lens_profile ==
nullptr) ||
211 (lens_profile !=
nullptr && (!local || selected != &handlers[0]))) {
212 std::cerr <<
"SODA: lens emulation requires --local --aicam --lens-profile "
216 if (positional.size() != 1 && positional.size() != 11) {
217 std::cerr <<
"SODA: expected IMAGE optionally followed by 10 shot integers"
221 for (
size_t index = 1; index < positional.size(); ++index) {
222 if (!is_shot_value(positional[index])) {
223 std::cerr <<
"SODA: invalid shot integer " << positional[index]
229 std::ifstream
image(positional[0], std::ios::binary | std::ios::ate);
231 std::cerr <<
"SODA: could not inspect image " << positional[0] << std::endl;
235 if (local) std::cerr <<
"SODA: development-PC mode (--local)" << std::endl;
236 std::string lens_output;
237 const char* analysis_image = positional[0];
238 if (lens_profile !=
nullptr) {
239 if (!emulate_lens(positional[0], lens_profile, lens_cache, lens_output)) {
240 std::cerr <<
"SODA: lens emulation failed; clean image retained, "
241 "analysis skipped\n";
244 analysis_image = lens_output.c_str();
245 std::cout <<
"SODA: lens-emulated analysis input " << analysis_image
257 std::cerr <<
"SODA: object post-processing incomplete; original retained\n";
260 if (selected !=
nullptr) {
263 std::cout <<
"SODA: I looked at the image. Cool, right?" << std::endl;
static void print_usage(FILE *stream, const char *program)
Print command-line help or version-led usage text.
bool image_lens_emulate(const char *application, const char *input, const char *profile, const char *cache, char *output, size_t capacity, const volatile sig_atomic_t *running)
static struct usher_camera_profile profile
int main(int argc, char *argv[])
Select and run the postprocessor for one saved camera image.
bool soda_process_object_detection(const char *image_path)
Post-process a captured image for an object-detection hit, if it has one.
EXIF-driven object-hit post-processing for SODA.
Compile-time build identity strings for USHER executables.
#define SODA_BUILD_VERSION
Validated capture and reporting policy, fixed before the sample loop.
struct captured_image image