24 #include <boost/algorithm/string.hpp> 25 #include <boost/program_options.hpp> 30 #include <linux/videodev2.h> 38 v4l2_queryctrl queryctrl;
39 v4l2_control control_s;
40 memset(&queryctrl, 0,
sizeof(queryctrl));
41 memset(&control_s, 0,
sizeof(control_s));
42 std::string package_name(
"tuw_uvc");
44 configfile = fopen(filename.c_str(),
"w");
45 fprintf(configfile,
"#! /usr/bin/env python\n");
46 fprintf(configfile,
"#Autogenerated V4L Dynamic Control\n\n");
47 fprintf(configfile,
"PACKAGE='%s'\n", package_name.c_str());
48 fprintf(configfile,
"from dynamic_reconfigure.parameter_generator_catkin import *\n");
49 fprintf(configfile,
"gen = ParameterGenerator()\n\n");
52 fprintf(configfile,
"gen.add(\"show_camera_image\", bool_t, 0, \"Show camera image\", True)\n");
53 fprintf(configfile,
"gen.add(\"camera_freeze\", bool_t, 0, \"Pulbishes the last image over and over again\", True)\n");
54 fprintf(configfile,
"enum_convert_image = gen.enum([gen.const(\"raw_data\", int_t, 0, \"raw camera Data\"),");
55 fprintf(configfile,
" gen.const(\"YUV422toRGB\", int_t, 1, \"converts image to rgb first\"),");
56 fprintf(configfile,
" gen.const(\"YUV422toBRG\", int_t, 2, \"converts image to bgr first\"),");
57 fprintf(configfile,
" gen.const(\"YUV422toGray\", int_t, 3, \"converts image to gray first\")], \"Convert image\")\n");
58 fprintf(configfile,
"gen.add(\"convert_image_first\", int_t, 3, \"Convets the raw image first to an other format\", 1, 0, 3, edit_method=enum_convert_image)\n");
61 fprintf(configfile,
"\n#Autogenerated Controls\n\n");
62 for(std::vector<V4RCam::ControlEntryPtr>::const_iterator it = controlEntries.begin(); it != controlEntries.end(); it++) {
63 queryctrl.id = (*it)->queryctrl->id;
65 if(0 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
66 if(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
69 if(queryctrl.type == V4L2_CTRL_TYPE_INTEGER) {
70 fprintf(configfile,
"gen.add(\"%s\", int_t, 0, \"%s\", %i, %i, %i)\n",
71 (*it)->varName.c_str(), queryctrl.name, queryctrl.default_value, queryctrl.minimum, queryctrl.maximum);
72 }
else if(queryctrl.type == V4L2_CTRL_TYPE_BOOLEAN) {
73 fprintf(configfile,
"gen.add(\"%s\", bool_t, 0, \"%s\", %s)\n",
74 (*it)->varName.c_str(), queryctrl.name, queryctrl.default_value ?
"True" :
"False");
75 }
else if(queryctrl.type == V4L2_CTRL_TYPE_MENU) {
76 fprintf(configfile,
"enum_%s = gen.enum([", (*it)->varName.c_str());
78 for(
int i = queryctrl.minimum; i <= queryctrl.maximum; i++) {
79 struct v4l2_querymenu qm;
83 boost::this_thread::sleep(boost::posix_time::milliseconds(10));
84 if(v4l2_ioctl(fd, VIDIOC_QUERYMENU, &qm) == 0) {
85 std::string menuEntryName = (
const char *)qm.name;
87 boost::algorithm::trim_left_if(menuEntryName, boost::algorithm::is_any_of(
"_"));
88 boost::algorithm::trim_right_if(menuEntryName, boost::algorithm::is_any_of(
"_"));
89 fprintf(configfile,
"gen.const(\"%s\", int_t, %i, \"%s\")",
90 menuEntryName.c_str(), i, (
const char *)qm.name);
92 fprintf(configfile,
"gen.const(\"Unkown%i\", int_t, %i, \"Unkown\")",
95 if(i != queryctrl.maximum) fprintf(configfile,
", ");
97 fprintf(configfile,
"], \"%s\")\n", queryctrl.name);
99 fprintf(configfile,
"gen.add(\"%s\", int_t, 0, \"%s\", %i, %i, %i, edit_method=enum_%s)\n",
100 (*it)->varName.c_str(), queryctrl.name, queryctrl.default_value, queryctrl.minimum, queryctrl.maximum, (*it)->varName.c_str());
101 }
else if(queryctrl.type == V4L2_CTRL_TYPE_BUTTON) {
102 }
else if(queryctrl.type == V4L2_CTRL_TYPE_INTEGER64) {
103 }
else if(queryctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) {
104 }
else if(queryctrl.type == V4L2_CTRL_TYPE_STRING) {
105 }
else if(queryctrl.type == V4L2_CTRL_TYPE_BITMASK) {
110 boost::this_thread::sleep(boost::posix_time::milliseconds(10));
112 fprintf(configfile,
"\nexit(gen.generate(PACKAGE, \"%s\", \"CameraParameters\"))\n", package_name.c_str());
115 std::cout <<
"Wrote file :" << filename << std::endl;
116 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
120 int main(
int argc,
char **argv)
122 namespace po = boost::program_options;
123 std::string filename;
125 po::options_description desc(
"Allowed Parameters");
127 (
"help",
"get this help message")
128 (
"device,d", po::value<std::string>(&device)->default_value(
"/dev/video0"),
"Video device")
129 (
"file,f", po::value<std::string>(&filename),
"File to genrate: like cfg/CameraParameters.cfg");
131 po::variables_map vm;
133 po::store(po::parse_command_line(argc, argv, desc), vm);
134 }
catch(
const std::exception &ex) {
135 std::cout << desc << std::endl;;
140 if(vm.count(
"help") || (vm.count(
"file") == 0)) {
141 std::cout << desc << std::endl;
145 std::cout <<
"File: " << filename << std::endl;
148 const std::vector<V4RCam::ControlEntryPtr > &controlEntries = v4lCam.
detectControlEnties();
149 for(
unsigned int i = 0; i < controlEntries.size(); i++) {
150 std::cout << controlEntries[i]->getQueryCtrlInfo() << std::endl;
152 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
154 boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
const std::vector< ControlEntryPtr > & detectControlEnties()
static char removeNonAlNum(char in)
FD initCamera(const std::string &videoDevice="")
vector of the current supported control entries