JeVois  1.9
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
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 
24 //! Add a new mapping to videomappings.cfg skipping duplicates
25 /*! This little app was created so that we ensure perfect consistency between the kernel driver and the user code by
26  using exactly the same config file parsing code (in VideoMapping). */
27 int main(int argc, char const* argv[])
28 {
29  jevois::logLevel = LOG_CRIT;
30 
31  if (argc != 11)
32  LFATAL("USAGE: jevois-add-videomapping <USBmode> <USBwidth> <USBheight> <USBfps> <CAMmode> "
33  "<CAMwidth> <CAMheight> <CAMfps> <Vendor> <Module>");
34 
35  // Create the new mapping. Here we are lenient and do not check for existence of the .so or .py file, as it may get
36  // installed later:
38  try
39  {
40  m.ofmt = jevois::strfcc(argv[1]);
41  m.ow = std::stoi(argv[2]);
42  m.oh = std::stoi(argv[3]);
43  m.ofps = std::stof(argv[4]);
44 
45  m.cfmt = jevois::strfcc(argv[5]);
46  m.cw = std::stoi(argv[6]);
47  m.ch = std::stoi(argv[7]);
48  m.cfps = std::stof(argv[8]);
49  }
50  catch (std::exception const & e) { LFATAL("Parsing error: " << e.what()); }
51  catch (...) { LFATAL("Unknown parsing error"); }
52 
53  m.vendor = argv[9];
54  m.modulename = argv[10];
55 
56  // Parse the videomappings.cfg file and create the mappings, do not check for .so/.py existence:
57  size_t defidx;
58  std::ifstream ifs(JEVOIS_ENGINE_CONFIG_FILE);
59  if (ifs.is_open() == false) LFATAL("Could not open [" << JEVOIS_ENGINE_CONFIG_FILE << ']');
60  std::vector<jevois::VideoMapping> mappings =
61  jevois::videoMappingsFromStream(jevois::CameraSensor::any, ifs, defidx, false);
62  ifs.close();
63 
64  // Check for match, ignoring the python field since we did not set it:
65  for (jevois::VideoMapping const & mm : mappings)
66  if (m.hasSameSpecsAs(mm) && m.vendor == mm.vendor && m.modulename == mm.modulename)
67  return 0; // We found it. Nothing to add and we are done.
68 
69  // Not found, so add one line to videomappings.cfg with the new mapping:
70  std::ofstream ofs(JEVOIS_ENGINE_CONFIG_FILE, std::ios_base::app);
71  if (ofs.is_open() == false) LFATAL("Could not write to [" << JEVOIS_ENGINE_CONFIG_FILE << ']');
72  ofs << std::endl << m << std::endl;
73 
74  return 0;
75 }
76 
bool hasSameSpecsAs(VideoMapping const &other) const
Equality operator for specs but not vendor or module name.
Definition: VideoMapping.C:99
float ofps
output frame rate in frames/sec
Definition: VideoMapping.H:48
unsigned int ofmt
output pixel format, or 0 for no output over USB
Definition: VideoMapping.H:45
std::string modulename
Name of the Module that will process this mapping.
Definition: VideoMapping.H:60
unsigned int ch
camera height
Definition: VideoMapping.H:52
Simple struct to hold video mapping definitions for the processing Engine.
Definition: VideoMapping.H:43
int logLevel
Current log level.
Definition: Log.C:28
unsigned int oh
output height
Definition: VideoMapping.H:47
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level. ...
Definition: Log.H:212
unsigned int cfmt
camera pixel format
Definition: VideoMapping.H:50
unsigned int cw
camera width
Definition: VideoMapping.H:51
int main(int argc, char const *argv[])
Add a new mapping to videomappings.cfg skipping duplicates.
unsigned int ow
output width
Definition: VideoMapping.H:46
std::string vendor
Module creator name, used as a directory to organize the modules.
Definition: VideoMapping.H:58
unsigned int strfcc(std::string const &str)
Convert a JeVois video format string to V4L2 four-cc code (V4L2_PIX_FMT_...)
Definition: Utils.C:79
float cfps
camera frame rate in frames/sec
Definition: VideoMapping.H:53