JeVois  1.21
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
jevois-add-videomapping.C
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18#include <jevois/Debug/Log.H>
20#include <jevois/Util/Utils.H>
21#include <fstream>
22#include <iostream>
23#include <sstream>
24
25//! Add a new mapping to videomappings.cfg skipping duplicates
26/*! This little app was created so that we ensure perfect consistency between the kernel driver and the user code by
27 using exactly the same config file parsing code (in VideoMapping). */
28int main(int argc, char const* argv[])
29{
30 jevois::logLevel = LOG_INFO;//CRIT;
31
32 if (argc != 11)
33 LFATAL("USAGE: jevois-add-videomapping <USBmode> <USBwidth> <USBheight> <USBfps> <CAMmode> "
34 "<CAMwidth> <CAMheight> <CAMfps> <Vendor> <Module>");
35
36 std::string args;
37 for (int i = 1; i < argc; ++i) { args += argv[i]; args += ' '; }
38 args += "\n";
39 std::stringstream ss(args);
40
41 // Create the new mapping by parsing the command-line args. Here we are lenient and do not check for existence of the
42 // .so or .py file, as it may get installed later, and we assume GUI is available:
43 size_t defidx;
44 std::vector<jevois::VideoMapping> vm =
45 jevois::videoMappingsFromStream(jevois::CameraSensor::any, ss, defidx, false, true);
46 if (vm.size() != 1)
47 LFATAL("Could not parse input args into a valid video mapping: [" << ss.str() << ']');
48 jevois::VideoMapping & m = vm[0];
49
50 // Parse the videomappings.cfg file and create the mappings, do not check for .so/.py existence, assume GUI exists:
51 std::ifstream ifs(JEVOIS_ENGINE_CONFIG_FILE);
52 if (ifs.is_open() == false) LFATAL("Could not open [" << JEVOIS_ENGINE_CONFIG_FILE << ']');
53 std::vector<jevois::VideoMapping> mappings =
54 jevois::videoMappingsFromStream(jevois::CameraSensor::any, ifs, defidx, false, true);
55 ifs.close();
56
57 // Check for match, ignoring the python field since we did not set it:
58 for (jevois::VideoMapping const & mm : mappings)
59 if (m.hasSameSpecsAs(mm) && m.wdr == mm.wdr && m.vendor == mm.vendor && m.modulename == mm.modulename)
60 return 0; // We found it. Nothing to add and we are done.
61
62 // Not found, so add one line to videomappings.cfg with the new mapping:
63 std::ofstream ofs(JEVOIS_ENGINE_CONFIG_FILE, std::ios_base::app);
64 if (ofs.is_open() == false) LFATAL("Could not write to [" << JEVOIS_ENGINE_CONFIG_FILE << ']');
65 ofs << std::endl << m << std::endl;
66
67 LINFO("Added [" << m.str() << "] to [" << JEVOIS_ENGINE_CONFIG_FILE << ']');
68
69 // Terminate logger:
71
72 return 0;
73}
74
#define JEVOIS_ENGINE_CONFIG_FILE
Location of the engine videomappings.cfg definition file.
Definition Config.H:94
int logLevel
Current log level.
Definition Log.C:29
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
Definition Log.H:230
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
Definition Log.H:194
int main(int argc, char const *argv[])
Add a new mapping to videomappings.cfg skipping duplicates.
void logEnd()
Terminate log service.
Definition Log.C:145
Simple struct to hold video mapping definitions for the processing Engine.
WDRtype wdr
Type of wide-dynamic-range (WDR) to use, if sensor supports it.
bool hasSameSpecsAs(VideoMapping const &other) const
Equality operator for specs but not vendor or module name.
std::string modulename
Name of the Module that will process this mapping.
std::string str() const
Convenience function to print out the whole mapping in a human-friendly way.
std::string vendor
Module creator name, used as a directory to organize the modules.