13 int32_t buffer_size,
const std::string &frame_id)
16 topic_name_(topic_name),
17 buffer_size_(buffer_size),
19 info_manager_(node_, frame_id),
20 capture_delay_(
ros::Duration(node_.
param(
"capture_delay", 0.0)))
41 std::stringstream stream;
42 stream <<
"property_" << i <<
"_code";
43 const std::string param_for_code = stream.str();
45 stream <<
"property_" << i <<
"_value";
46 const std::string param_for_value = stream.str();
51 if (!
cap_.set(code, value))
53 ROS_ERROR_STREAM(
"Setting with code " << code <<
" and value " << value <<
" failed" 61 double width_coeff =
static_cast<double>(width) /
info_.width;
62 double height_coeff = static_cast<double>(height) /
info_.height;
64 info_.height = height;
67 info_.K[0] *= width_coeff;
68 info_.K[2] *= width_coeff;
69 info_.K[4] *= height_coeff;
70 info_.K[5] *= height_coeff;
72 info_.P[0] *= width_coeff;
73 info_.P[2] *= width_coeff;
74 info_.P[5] *= height_coeff;
75 info_.P[6] *= height_coeff;
83 std::stringstream stream;
84 stream <<
"device_id" << device_id <<
" cannot be opened";
94 cap_.open(device_path, cv::CAP_V4L);
97 throw DeviceError(
"device_path " + device_path +
" cannot be opened");
111 cap_.open(file_path);
112 if (!
cap_.isOpened())
114 std::stringstream stream;
115 stream <<
"file " << file_path <<
" cannot be opened";
149 int old_width =
info_.width;
150 int old_height =
info_.height;
152 ROS_INFO_ONCE(
"Camera calibration automatically rescaled from %dx%d to %dx%d",
157 ROS_WARN_ONCE(
"Calibration resolution %dx%d does not match camera resolution %dx%d. " 158 "Use rescale_camera_info param for rescaling",
162 info_.header.stamp = stamp;
182 ROS_INFO(
"setting property %s = %lf", param_name.c_str(), value);
183 return cap_.set(property_id, value);
image_transport::ImageTransport it_
ROS image transport utility.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
bool capture()
capture an image and store.
sensor_msgs::CameraInfo getCameraInfo(void)
#define ROS_INFO_ONCE(...)
Capture(ros::NodeHandle &node, const std::string &topic_name, int32_t buffer_size, const std::string &frame_id)
costruct with ros node and topic settings
bool loadCameraInfo(const std::string &url)
void open()
Open default camera device.
ros::NodeHandle node_
node handle for advertise.
ROS cv camera device exception.
void publish()
Publish the image that is already captured by capture().
image_transport::CameraPublisher pub_
image publisher created by image_transport::ImageTransport.
void loadCameraInfo()
Load camera info from file.
bool validateURL(const std::string &url)
int32_t buffer_size_
size of publisher buffer
CameraPublisher advertiseCamera(const std::string &base_topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_ONCE(...)
camera_info_manager::CameraInfoManager info_manager_
camera info manager
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
namespace of this package
cv_bridge::CvImage bridge_
this stores last captured image.
void openFile(const std::string &file_path)
open video file instead of capture device.
std::string topic_name_
name of topic without namespace (usually "image_raw").
cv::VideoCapture cap_
capture device.
bool setPropertyFromParam(int property_id, const std::string ¶m_name)
set CV_PROP_*
bool getParam(const std::string &key, std::string &s) const
ros::Duration capture_delay_
capture_delay param value
std::string frame_id_
header.frame_id for publishing images.
void rescaleCameraInfo(int width, int height)
rescale camera calibration to another resolution
#define ROS_ERROR_STREAM(args)
const sensor_msgs::ImagePtr getImageMsgPtr() const
accessor of ROS Image message.
sensor_msgs::CameraInfo info_
this stores last captured image info.
bool rescale_camera_info_
rescale_camera_info param value