1 #include <boost/thread.hpp> 7 #include "sensor_msgs/Image.h" 9 #include "sensor_msgs/CameraInfo.h" 23 control_mod(uint32_t
id, int32_t val,
const std::string& name) {
33 static inline void rotate(
unsigned char *dst_chr,
unsigned char *src_chr,
int pixels) {
35 unsigned char r, g, b;
38 struct pixel_t *src = (pixel_t *) src_chr;
39 struct pixel_t *dst = &(((pixel_t *) dst_chr)[pixels - 1]);
41 for (
int i = pixels; i != 0; --i) {
51 node(comm_nh), pnode(param_nh), it(comm_nh),
52 left_info_mgr(
ros::NodeHandle(comm_nh,
"left"),
"left_camera"),
53 right_info_mgr(
ros::NodeHandle(comm_nh,
"right"),
"right_camera") {
68 std::string left_url, right_url;
111 cam_left->set_v4l2_control(V4L2_CID_FOCUS_AUTO, auto_focus,
"auto_focus");
117 cam_left->set_v4l2_control(V4L2_CID_FOCUS_ABSOLUTE, focus_absolute,
"focus_absolute");
125 val = V4L2_EXPOSURE_AUTO;
127 val = V4L2_EXPOSURE_MANUAL;
129 cam_left->set_v4l2_control(V4L2_CID_EXPOSURE_AUTO, val,
"auto_exposure");
133 int exposure_absolute;
134 if (
pnode.
getParam(
"exposure_absolute", exposure_absolute)) {
135 cam_left->set_v4l2_control(V4L2_CID_EXPOSURE_ABSOLUTE, exposure_absolute,
"exposure_absolute");
141 cam_left->set_v4l2_control(V4L2_CID_BRIGHTNESS, brightness,
"brightness");
145 int power_line_frequency;
146 if (
pnode.
getParam(
"power_line_frequency", power_line_frequency)) {
148 if (power_line_frequency == 0) {
149 val = V4L2_CID_POWER_LINE_FREQUENCY_DISABLED;
150 }
else if (power_line_frequency == 50) {
151 val = V4L2_CID_POWER_LINE_FREQUENCY_50HZ;
152 }
else if (power_line_frequency == 60) {
153 val = V4L2_CID_POWER_LINE_FREQUENCY_60HZ;
155 printf(
"power_line_frequency=%d not supported. Using auto.\n", power_line_frequency);
156 val = V4L2_CID_POWER_LINE_FREQUENCY_AUTO;
158 cam_left->set_v4l2_control(V4L2_CID_POWER_LINE_FREQUENCY, val,
"power_line_frequency");
186 info_left->header.stamp = time;
187 info_right->header.stamp = time;
188 info_left->header.frame_id =
frame;
189 info_right->header.frame_id =
frame;
197 unsigned int pair_id = 0;
199 unsigned char *frame_left = NULL, *frame_right = NULL;
200 uint32_t bytes_used_left, bytes_used_right;
204 int left_idx =
cam_left->
grab(&frame_left, bytes_used_left);
205 int right_idx =
cam_right->
grab(&frame_right, bytes_used_right);
213 if (frame_left && frame_right) {
214 ImagePtr image_left(
new Image);
215 ImagePtr image_right(
new Image);
217 image_left->height =
height;
218 image_left->width =
width;
219 image_left->step = 3 *
width;
220 image_left->encoding = image_encodings::RGB8;
221 image_left->header.stamp = capture_time;
222 image_left->header.seq = pair_id;
224 image_right->height =
height;
225 image_right->width =
width;
226 image_right->step = 3 *
width;
227 image_right->encoding = image_encodings::RGB8;
228 image_right->header.stamp = capture_time;
229 image_right->header.seq = pair_id;
231 image_left->header.frame_id =
frame;
232 image_right->header.frame_id =
frame;
234 image_left->data.resize(image_left->step * image_left->height);
235 image_right->data.resize(image_right->step * image_right->height);
240 memcpy(&image_left->data[0], frame_left,
width * height * 3);
243 rotate(&image_right->data[0], frame_right,
width * height);
245 memcpy(&image_right->data[0], frame_right,
width * height * 3);
void release(unsigned buf_idx)
camera_info_manager::CameraInfoManager left_info_mgr
sensor_msgs::CameraInfo getCameraInfo(void)
void publish(const boost::shared_ptr< M > &message) const
image_transport::Publisher right_pub
bool loadCameraInfo(const std::string &url)
bool set_v4l2_control(int id, int value, const std::string &name)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
boost::thread image_thread
void sendInfo(ros::Time time)
image_transport::ImageTransport it
ros::Publisher left_info_pub
ros::Publisher right_info_pub
image_transport::Publisher left_pub
void publish(const sensor_msgs::Image &message) const
void set_motion_thresholds(int lum, int count)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static void rotate(unsigned char *dst_chr, unsigned char *src_chr, int pixels)
bool getParam(const std::string &key, std::string &s) const
control_mod(uint32_t id, int32_t val, const std::string &name)
camera_info_manager::CameraInfoManager right_info_mgr
int grab(unsigned char **frame, uint32_t &bytes_used)