70 #include <dynamic_reconfigure/server.h> 71 #include <uavc_v4lctl/v4lctlNodeDynConfig.h> 72 #include <uavc_v4lctl/v4lctlSet.h> 73 #include <uavc_v4lctl/v4lctlGet.h> 74 #include <opencv2/opencv.hpp> 75 #include <boost/algorithm/string/replace.hpp> 76 #include <boost/regex.hpp> 80 #define YAML_OPT_TO_NAME(s) boost::replace_all_copy(boost::replace_all_copy(s,"\"","-")," ","_") 81 #define YAML_NAME_TO_OPT(s) boost::replace_all_copy(boost::replace_all_copy(s,"-","\""),"_"," ") 95 std::map<std::string, std::string>
fs_map_;
106 pnh.
param<std::string>(
"device",
device_,
"/dev/video0");
122 if (!yaml_.empty() && fs.open(yaml_, cv::FileStorage::WRITE))
124 std::map<std::string, std::string>::iterator it = fs_map_.begin();
126 while (it != fs_map_.end())
128 std::string key = (*it).first;
130 fs << key << fs_map_[key];
141 std::stringstream ss;
143 ss <<
"v4lctl -c " << device_ <<
" show \"" << name <<
"\"";
145 if ((pipe=popen(ss.str().c_str(),
"r")))
147 if (fgets(stdout,
sizeof(stdout), pipe))
148 result = boost::regex_replace(std::string(stdout), boost::regex(
"^" + name +
": ([a-zA-Z0-9\\-]+).*"),
"$1");
162 std::stringstream ss;
165 ss <<
"v4lctl -c " << device_ <<
" " << name <<
" " << value;
169 if ((result=std::system(ss.str().c_str()) > -1))
179 if (fs.open(yaml_, cv::FileStorage::READ))
181 cv::FileNode fn = fs.root();
183 for (cv::FileNodeIterator fit = fn.begin(); fit != fn.end(); fit++)
185 cv::FileNode item = *fit;
192 void initConfig(v4lctlNodeDynConfig &config,
bool defaults =
false)
196 #define V4LCTL_GET_PERCENT(name,default,max) (defaults || (s=v4lctlGet(name)).empty() ? default : (atoi(s.c_str()) * 100 / max)) 197 #define V4LCTL_GET_BOOL(name,default) (defaults || (s=v4lctlGet(name)).empty() ? default : boost::regex_match(s, boost::regex("^on$"))) 198 #define V4LCTL_GET_INT(name,default) (defaults || (s=v4lctlGet(name)).empty() ? default : atoi(s.c_str())) 199 #define V4LCTL_GET_STRING(name,default) (defaults || (s=v4lctlGet(name)).empty() ? default : s) 222 void configCb(v4lctlNodeDynConfig &config,
int level)
229 ROS_INFO(
"Reconfigure server initialized");
234 if (config.Set_Defaults)
237 config.Set_Defaults =
false;
240 if (config.input != cfg_.input)
241 v4lctlSet(
"setattr input", config.input);
243 if (config.norm != cfg_.norm)
246 if (config.bright != cfg_.bright)
247 v4lctlSet(
"bright", std::to_string(config.bright)+
'%');
249 if (config.contrast != cfg_.contrast)
250 v4lctlSet(
"contrast", std::to_string(config.contrast)+
'%');
252 if (config.color != cfg_.color)
253 v4lctlSet(
"color", std::to_string(config.color)+
'%');
255 if (config.hue != cfg_.hue)
256 v4lctlSet(
"hue", std::to_string(config.hue)+
'%');
258 if (config.UV_Ratio != cfg_.UV_Ratio)
259 v4lctlSet(
"setattr \"UV Ratio\"", std::to_string(config.UV_Ratio)+
'%');
261 if (config.Coring != cfg_.Coring)
262 v4lctlSet(
"setattr Coring", std::to_string(config.Coring));
264 if (config.Whitecrush_Lower != cfg_.Whitecrush_Lower)
265 v4lctlSet(
"setattr \"Whitecrush Lower\"", std::to_string(config.Whitecrush_Lower)+
'%');
267 if (config.Whitecrush_Upper != cfg_.Whitecrush_Upper)
268 v4lctlSet(
"setattr \"Whitecrush Upper\"", std::to_string(config.Whitecrush_Upper)+
'%');
270 if (config.mute != cfg_.mute)
271 v4lctlSet(
"setattr mute", config.mute ?
"on" :
"off");
273 if (config.Chroma_AGC != cfg_.Chroma_AGC)
274 v4lctlSet(
"setattr \"Chroma AGC\"", config.Chroma_AGC ?
"on" :
"off");
276 if (config.Color_Killer != cfg_.Color_Killer)
277 v4lctlSet(
"setattr \"Color Killer\"", config.Color_Killer ?
"on" :
"off");
279 if (config.Comb_Filter != cfg_.Comb_Filter)
280 v4lctlSet(
"setattr \"Comb Filter\"", config.Comb_Filter ?
"on" :
"off");
282 if (config.Auto_Mute != cfg_.Auto_Mute)
283 v4lctlSet(
"setattr \"Auto Mute\"", config.Auto_Mute ?
"on" :
"off");
285 if (config.Luma_Decim != cfg_.Luma_Decim)
286 v4lctlSet(
"setattr \"Luma Decimation Filter\"", config.Luma_Decim ?
"on" :
"off");
288 if (config.AGC_Crush != cfg_.AGC_Crush)
289 v4lctlSet(
"setattr \"AGC Crush\"", config.AGC_Crush ?
"on" :
"off");
291 if (config.VCR_Hack != cfg_.VCR_Hack)
292 v4lctlSet(
"setattr \"VCR Hack\"", config.VCR_Hack ?
"on" :
"off");
294 if (config.Full_Luma != cfg_.Full_Luma)
295 v4lctlSet(
"setattr \"Full Luma Range\"", config.Full_Luma ?
"on" :
"off");
300 bool v4lctlGetCb(v4lctlGet::Request &req, v4lctlGet::Response &res)
307 bool v4lctlSetCb(v4lctlSet::Request &req, v4lctlSet::Response &res)
315 int main(
int argc,
char **argv)
dynamic_reconfigure::Server< v4lctlNodeDynConfig > cfg_server_
ros::ServiceServer srv_v4lctl_set_
bool v4lctlSet(std::string name, std::string value)
ros::ServiceServer srv_v4lctl_get_
std::map< std::string, std::string > fs_map_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define V4LCTL_GET_BOOL(name, default)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
#define V4LCTL_GET_PERCENT(name, default, max)
#define YAML_NAME_TO_OPT(s)
std::string v4lctlGet(std::string name)
bool v4lctlSetCb(v4lctlSet::Request &req, v4lctlSet::Response &res)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void initConfig(v4lctlNodeDynConfig &config, bool defaults=false)
#define YAML_OPT_TO_NAME(s)
#define ROS_INFO_STREAM(args)
#define V4LCTL_GET_INT(name, default)
bool v4lctlGetCb(v4lctlGet::Request &req, v4lctlGet::Response &res)
int main(int argc, char **argv)
#define ROS_ERROR_STREAM(args)
#define V4LCTL_GET_STRING(name, default)
void configCb(v4lctlNodeDynConfig &config, int level)