Go to the documentation of this file.00001
00002
00003 #include "cv_camera/driver.h"
00004 #include <string>
00005
00006 namespace
00007 {
00008 const double DEFAULT_RATE = 30.0;
00009 const int32_t PUBLISHER_BUFFER_SIZE = 1;
00010 }
00011
00012 namespace cv_camera
00013 {
00014
00015 Driver::Driver(ros::NodeHandle& private_node,
00016 ros::NodeHandle& camera_node) :
00017 private_node_(private_node),
00018 camera_node_(camera_node)
00019 {
00020 }
00021
00022 void Driver::setup()
00023 {
00024 double hz(DEFAULT_RATE);
00025 int32_t device_id(0);
00026 std::string device_path("");
00027 std::string frame_id("camera");
00028 std::string file_path("");
00029
00030 private_node_.getParam("device_id", device_id);
00031 private_node_.getParam("frame_id", frame_id);
00032 private_node_.getParam("rate", hz);
00033
00034 int32_t image_width(640);
00035 int32_t image_height(480);
00036
00037 camera_.reset(new Capture(camera_node_,
00038 "image_raw",
00039 PUBLISHER_BUFFER_SIZE,
00040 frame_id));
00041
00042 if (private_node_.getParam("file", file_path) && file_path != "")
00043 {
00044 camera_->openFile(file_path);
00045 } else if (private_node_.getParam("device_path", device_path) && device_path != "")
00046 {
00047 camera_->open(device_path);
00048 }
00049 else
00050 {
00051 camera_->open(device_id);
00052 }
00053 if (private_node_.getParam("image_width", image_width))
00054 {
00055 if (!camera_->setWidth(image_width))
00056 {
00057 ROS_WARN("fail to set image_width");
00058 }
00059 }
00060 if (private_node_.getParam("image_height", image_height))
00061 {
00062 if (!camera_->setHeight(image_height))
00063 {
00064 ROS_WARN("fail to set image_height");
00065 }
00066 }
00067
00068 camera_->setPropertyFromParam(CV_CAP_PROP_POS_MSEC, "cv_cap_prop_pos_msec");
00069 camera_->setPropertyFromParam(CV_CAP_PROP_POS_AVI_RATIO, "cv_cap_prop_pos_avi_ratio");
00070 camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_WIDTH, "cv_cap_prop_frame_width");
00071 camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_HEIGHT, "cv_cap_prop_frame_height");
00072 camera_->setPropertyFromParam(CV_CAP_PROP_FPS, "cv_cap_prop_fps");
00073 camera_->setPropertyFromParam(CV_CAP_PROP_FOURCC, "cv_cap_prop_fourcc");
00074 camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_COUNT, "cv_cap_prop_frame_count");
00075 camera_->setPropertyFromParam(CV_CAP_PROP_FORMAT, "cv_cap_prop_format");
00076 camera_->setPropertyFromParam(CV_CAP_PROP_MODE, "cv_cap_prop_mode");
00077 camera_->setPropertyFromParam(CV_CAP_PROP_BRIGHTNESS, "cv_cap_prop_brightness");
00078 camera_->setPropertyFromParam(CV_CAP_PROP_CONTRAST, "cv_cap_prop_contrast");
00079 camera_->setPropertyFromParam(CV_CAP_PROP_SATURATION, "cv_cap_prop_saturation");
00080 camera_->setPropertyFromParam(CV_CAP_PROP_HUE, "cv_cap_prop_hue");
00081 camera_->setPropertyFromParam(CV_CAP_PROP_GAIN, "cv_cap_prop_gain");
00082 camera_->setPropertyFromParam(CV_CAP_PROP_EXPOSURE, "cv_cap_prop_exposure");
00083 camera_->setPropertyFromParam(CV_CAP_PROP_CONVERT_RGB, "cv_cap_prop_convert_rgb");
00084
00085 camera_->setPropertyFromParam(CV_CAP_PROP_RECTIFICATION, "cv_cap_prop_rectification");
00086 camera_->setPropertyFromParam(CV_CAP_PROP_ISO_SPEED, "cv_cap_prop_iso_speed");
00087 #ifdef CV_CAP_PROP_WHITE_BALANCE_U
00088 camera_->setPropertyFromParam(CV_CAP_PROP_WHITE_BALANCE_U, "cv_cap_prop_white_balance_u");
00089 #endif // CV_CAP_PROP_WHITE_BALANCE_U
00090 #ifdef CV_CAP_PROP_WHITE_BALANCE_V
00091 camera_->setPropertyFromParam(CV_CAP_PROP_WHITE_BALANCE_V, "cv_cap_prop_white_balance_v");
00092 #endif // CV_CAP_PROP_WHITE_BALANCE_V
00093 #ifdef CV_CAP_PROP_BUFFERSIZE
00094 camera_->setPropertyFromParam(CV_CAP_PROP_BUFFERSIZE, "cv_cap_prop_buffersize");
00095 #endif // CV_CAP_PROP_BUFFERSIZE
00096
00097 rate_.reset(new ros::Rate(hz));
00098 }
00099
00100 void Driver::proceed()
00101 {
00102 if (camera_->capture())
00103 {
00104 camera_->publish();
00105 }
00106 rate_->sleep();
00107 }
00108
00109 Driver::~Driver()
00110 {
00111 }
00112
00113 }