threshold_imshow.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 
3 #include <opencv2/core/core.hpp>
4 #include <opencv2/highgui/highgui.hpp>
5 #include <opencv2/imgproc/imgproc.hpp>
6 
7 #include <cv_bridge/cv_bridge.h>
8 
9 #include <image_transport/image_transport.h>
10 
11 #include <sensor_msgs/image_encodings.h>
12 
13 using namespace std;
14 using namespace cv;
15 namespace enc = sensor_msgs::image_encodings;
16 
17 class ImageConverter
18 {
19  ros::NodeHandle nh_;
20  image_transport::ImageTransport it_;
21  image_transport::Subscriber image_sub_;
22 
23  public:
24 
26  : it_(nh_)
27  {
28  ros::NodeHandle nh_local("~");
29 
30  image_sub_ = it_.subscribe("/xb3/right/new_info/image_rect_color", 1, &ImageConverter::imageCb, this);
31  }
32 
34  {
35 
36  }
37 
38 
39  void imageCb(const sensor_msgs::ImageConstPtr& cam_msg)
40  {
41  cv_bridge::CvImagePtr cv_ptr;
42  try
43  {
44  cv_ptr = cv_bridge::toCvCopy(cam_msg, enc::BGR8);
45  }
46  catch (cv_bridge::Exception& e)
47  {
48  ROS_ERROR("cv_bridge exception: %s", e.what());
49  return;
50  }
51 // imshow("input4", cv_ptr->image);
52  // Convert code to ros, to subscrive image and laser data
53 
54 // Mat input = imread("/home/asus/workingcopies/lar4/src/perception/pedestrians/multimodal_pedestrian_detect/images/frame0009.jpg", CV_LOAD_IMAGE_COLOR);
55 
56  Mat input = cv_ptr->image;
57 
58  //Grayscale matrix
59  Mat grayscaleMat(input.size(), CV_8UC1);
60 
61  cvtColor(input, grayscaleMat, CV_BGR2GRAY);
62  threshold(grayscaleMat, grayscaleMat, 170, 255, THRESH_BINARY);
63 
64  imshow("drawing1", grayscaleMat);
65  waitKey(2);
66 
67  }
68 };
69 
70 int main(int argc, char** argv)
71 {
72  ros::init(argc, argv, "threshold_imshow_node");
73 
74  ImageConverter ic;
75 
76  cout << "estou aqui" << endl;
77 
78  ros::spin();
79  return 0;
80 }
void imageCb(const sensor_msgs::ImageConstPtr &cam_msg)
int main(int argc, char **argv)


multimodal_pedestrian_detect
Author(s): Rui Azevedo
autogenerated on Mon Mar 2 2015 01:32:27