1 #include <boost/thread.hpp> 7 #include "sensor_msgs/Image.h" 8 #include "sensor_msgs/CompressedImage.h" 10 #include "sensor_msgs/CameraInfo.h" 21 node(_comm_nh), pnode(_param_nh), it(_comm_nh),
22 info_mgr(_comm_nh,
"camera"), cam(0) {
36 std::string url, camera_name;
38 pnode.
param<std::string>(
"camera_name", camera_name,
"camera");
85 val = V4L2_EXPOSURE_AUTO;
87 val = V4L2_EXPOSURE_MANUAL;
92 int exposure_auto_priority;
93 if (
pnode.
getParam(
"exposure_auto_priority", exposure_auto_priority)) {
94 cam->
set_v4l2_control(V4L2_CID_EXPOSURE_AUTO_PRIORITY, exposure_auto_priority,
"exposure_auto_priority");
97 int exposure_absolute;
112 int power_line_frequency;
113 if (
pnode.
getParam(
"power_line_frequency", power_line_frequency)) {
115 if (power_line_frequency == 0) {
116 val = V4L2_CID_POWER_LINE_FREQUENCY_DISABLED;
117 }
else if (power_line_frequency == 50) {
118 val = V4L2_CID_POWER_LINE_FREQUENCY_50HZ;
119 }
else if (power_line_frequency == 60) {
120 val = V4L2_CID_POWER_LINE_FREQUENCY_60HZ;
122 printf(
"power_line_frequency=%d not supported. Using auto.\n", power_line_frequency);
123 val = V4L2_CID_POWER_LINE_FREQUENCY_AUTO;
143 bool auto_white_balance;
144 if (
pnode.
getParam(
"auto_white_balance", auto_white_balance)) {
145 cam->
set_v4l2_control(V4L2_CID_AUTO_WHITE_BALANCE, auto_white_balance,
"auto_white_balance");
148 int white_balance_tmp;
149 if (
pnode.
getParam(
"white_balance_temperature", white_balance_tmp)) {
150 cam->
set_v4l2_control(V4L2_CID_WHITE_BALANCE_TEMPERATURE, white_balance_tmp,
"white_balance_temperature");
164 if (
pnode.
getParam(
"backlight_compensation", backlight_comp)) {
165 cam->
set_v4l2_control(V4L2_CID_BACKLIGHT_COMPENSATION, backlight_comp,
"backlight_compensation");
202 if (info->K[0] != 0.0 &&
203 (image->width != info->width
204 || image->height != info->height)) {
205 info.reset(
new CameraInfo());
209 if (info->K[0] == 0.0) {
210 info->width = image->width;
211 info->height = image->height;
214 info->header.stamp = time;
215 info->header.frame_id =
frame;
222 info->header.stamp = time;
223 info->header.frame_id =
frame;
229 unsigned int pair_id = 0;
231 unsigned char *img_frame = NULL;
236 int idx =
cam->
grab(&img_frame, bytes_used);
243 if (img_frame &&
format !=
"jpeg") {
244 ImagePtr image(
new Image);
247 image->width =
width;
248 image->step = 3 *
width;
249 image->encoding = image_encodings::RGB8;
251 image->header.stamp = capture_time;
252 image->header.seq = pair_id;
254 image->header.frame_id =
frame;
256 image->data.resize(image->step * image->height);
258 memcpy(&image->data[0], img_frame,
width*
height * 3);
265 }
else if (img_frame &&
format ==
"jpeg") {
266 CompressedImagePtr image(
new CompressedImage);
268 image->header.stamp = capture_time;
269 image->header.seq = pair_id;
271 image->header.frame_id =
frame;
273 image->data.resize(bytes_used);
275 memcpy(&image->data[0], img_frame, bytes_used);
image_transport::Publisher pub
camera_info_manager::CameraInfoManager info_mgr
void release(unsigned buf_idx)
sensor_msgs::CameraInfo getCameraInfo(void)
void publish(const boost::shared_ptr< M > &message) const
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)
void publish(const sensor_msgs::Image &message) const
boost::thread image_thread
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void set_motion_thresholds(int lum, int count)
void sendInfo(sensor_msgs::ImagePtr &image, ros::Time time)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
image_transport::ImageTransport it
bool getParam(const std::string &key, std::string &s) const
void sendInfoJpeg(ros::Time time)
int grab(unsigned char **frame, uint32_t &bytes_used)
bool setCameraName(const std::string &cname)