Go to the documentation of this file.00001 #include <ros/ros.h>
00002
00003 #include <cv_bridge/cv_bridge.h>
00004 #include <opencv/cv.h>
00005 #include <sensor_msgs/image_encodings.h>
00006 #include <image_transport/image_transport.h>
00007
00008 using namespace std;
00009
00010 image_transport::CameraSubscriber camera_sub;
00011 image_transport::Publisher output_pub;
00012 cv_bridge::CvImagePtr cv_img;
00013
00014 void doOverlay(const sensor_msgs::ImageConstPtr& img_msg,
00015 const sensor_msgs::CameraInfoConstPtr& info_msg) {
00016
00017
00018 cv_img = cv_bridge::toCvCopy(img_msg, sensor_msgs::image_encodings::RGB8);
00019 cv::Mat input(cv_img->image.rows, cv_img->image.cols, CV_8UC1);
00020 cv_bridge::CvImage new_cv_img;
00021 new_cv_img.image = cv::Mat(cv_img->image.rows, cv_img->image.cols, CV_8UC1);
00022 double black_cap, white_cap;
00023 ros::param::param<double>("~black_cap", black_cap, 50);
00024 ros::param::param<double>("~white_cap", white_cap, 150);
00025 for(int j=0;j<cv_img->image.cols;j++)
00026 for(int i=0;i<cv_img->image.rows;i++) {
00027 double inten = (cv_img->image.at<cv::Vec3b>(i, j)[0] +
00028 cv_img->image.at<cv::Vec3b>(i, j)[1] +
00029 cv_img->image.at<cv::Vec3b>(i, j)[2])/3.;
00030 inten = 255.0 / (white_cap - black_cap) * (inten - black_cap);
00031 inten = max(0.0, min(inten, 255.0));
00032 input.at<uint8_t>(i, j) = (uint8_t) inten;
00033 }
00034
00035 new_cv_img.image = input;
00036
00037 new_cv_img.header = cv_img->header;
00038 new_cv_img.encoding = sensor_msgs::image_encodings::MONO8;
00039 output_pub.publish(new_cv_img.toImageMsg());
00040 }
00041
00042 int main(int argc, char **argv)
00043 {
00044 ros::init(argc, argv, "ar_servo_image_proc");
00045 ros::NodeHandle nh;
00046 image_transport::ImageTransport img_trans(nh);
00047
00048 camera_sub = img_trans.subscribeCamera("/camera", 1,
00049 &doOverlay);
00050 output_pub = img_trans.advertise("/output", 1);
00051
00052 ros::spin();
00053
00054 return 0;
00055 }