2 #include <boost/shared_ptr.hpp> 6 #include "sensor_msgs/Image.h" 7 #include "sensor_msgs/CameraInfo.h" 13 #define targetWidth 500 14 #define targetHeight 500 35 bool enable_controller_info =
false;
45 virtual void onDeviceChange(
const Controller&);
46 virtual void onServiceConnect(
const Controller&);
47 virtual void onServiceDisconnect(
const Controller&);
53 _left_node = boost::make_shared<ros::NodeHandle>(
"left");
54 _right_node = boost::make_shared<ros::NodeHandle>(
"right");
56 _pub_image_left = _left_node->advertise<sensor_msgs::Image>(
"image_raw", 1);
57 _pub_image_right = _right_node->advertise<sensor_msgs::Image>(
"image_raw", 1);
59 _pub_info_left = _left_node->advertise<sensor_msgs::CameraInfo>(
"camera_info", 1);
60 _pub_info_right = _right_node->advertise<sensor_msgs::CameraInfo>(
"camera_info", 1);
65 std::string default_l_info_filename;
66 std::string default_r_info_filename;
67 std::vector<std::string> search_path;
70 rp.
crawl(search_path, 1);
72 if ( rp.
find(
"leap_motion",path) ==
true)
74 default_l_info_filename = path + std::string(
"/config/camera_info/leap_cal_left.yml");
75 default_r_info_filename = path + std::string(
"/config/camera_info/leap_cal_right.yml");
79 default_l_info_filename =
"";
80 default_r_info_filename =
"";
84 std::string l_info_filename;
85 std::string r_info_filename;
87 local_nh.param(
"template_filename_left", l_info_filename, default_l_info_filename);
88 local_nh.param(
"template_filename_right", r_info_filename, default_r_info_filename);
90 l_info_filename = std::string(
"file://") + l_info_filename;
91 r_info_filename = std::string(
"file://") + r_info_filename;
98 ROS_INFO(
"CameraListener initialized");
105 ROS_INFO(
"CameraListener connected");
112 ROS_INFO(
"CameraListener disconnected");
129 sensor_msgs::Image image_msg;
131 image_msg.header.seq = seq++;
135 image_msg.encoding =
"mono8";
136 image_msg.is_bigendian = 0;
138 for(
int camera_num = 0; camera_num < 2; camera_num++){
139 Image image = images[camera_num];
152 #pragma omp parallel for 163 if(pixel.
x >= 0 && pixel.
x < image.
width() && pixel.
y >= 0 && pixel.
y < image.
height())
165 int data_index = floor(pixel.
y) * image.
width() + floor(pixel.
x);
166 image_msg.data[cutWidth*j+i] = image.
data()[data_index];
169 image_msg.data[cutWidth*j+i] = 0;
175 sensor_msgs::CameraInfoPtr info_msg(
new sensor_msgs::CameraInfo(info_mgr_left -> getCameraInfo() ) );
177 image_msg.header.frame_id = info_msg->header.frame_id =
"leap_pointcloud";
178 info_msg->width = image_msg.width;
179 info_msg->height = image_msg.height;
180 info_msg->header.stamp = image_msg.header.stamp;
181 info_msg->header.seq = image_msg.header.seq;
182 _pub_image_left.publish(image_msg);
183 _pub_info_left.publish(*info_msg);
187 sensor_msgs::CameraInfoPtr info_msg(
new sensor_msgs::CameraInfo(info_mgr_right->getCameraInfo()));
188 image_msg.header.frame_id = info_msg->header.frame_id =
"lmc_";
189 info_msg->width = image_msg.width;
190 info_msg->height = image_msg.height;
191 info_msg->header.stamp = image_msg.header.stamp;
192 info_msg->header.seq = image_msg.header.seq;
193 _pub_image_right.publish(image_msg);
194 _pub_info_right.publish(*info_msg);
202 ROS_INFO(
"CameraListener gained focus");
209 ROS_INFO(
"CameraListener lost focus");
216 ROS_INFO(
"CameraListener device changed");
218 for (
int i = 0; i < devices.
count(); ++i) {
219 ROS_INFO(
"id: %s", devices[i].toString().c_str() );
220 ROS_INFO(
" isStreaming: %s", (devices[i].isStreaming() ?
"true" :
"false") );
228 ROS_INFO(
"CameraListener service connected");
235 ROS_INFO(
"CameraListener service disconnected");
239 int main(
int argc,
char** argv) {
LEAP_EXPORT void setPolicyFlags(PolicyFlag flags) const
bool enable_controller_info
LEAP_EXPORT bool addListener(Listener &listener)
virtual void onFrame(const Controller &)
virtual void onExit(const Controller &)
virtual void onDeviceChange(const Controller &)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
virtual void onInit(const Controller &)
virtual void onServiceDisconnect(const Controller &)
ROSCPP_DECL void spin(Spinner &spinner)
LEAP_EXPORT Vector warp(const Vector &xy) const
LEAP_EXPORT float rayScaleX() const
LEAP_EXPORT float rayOffsetY() const
bool getSearchPathFromEnv(std::vector< std::string > &sp)
LEAP_EXPORT int count() const
void crawl(std::vector< std::string > search_path, bool force)
int main(int argc, char **argv)
virtual void onFocusGained(const Controller &)
bool find(const std::string &name, std::string &path)
LEAP_EXPORT bool removeListener(Listener &listener)
virtual void onConnect(const Controller &)
LEAP_EXPORT float rayOffsetX() const
LEAP_EXPORT Frame frame(int history=0) const
virtual void onServiceConnect(const Controller &)
LEAP_EXPORT float rayScaleY() const
virtual void onFocusLost(const Controller &)
virtual void onDisconnect(const Controller &)