clientimg_channels.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
27 #include "peddetect.h"
28 
29 class ImageConverter
30 {
31  ros::NodeHandle nh_;
32  image_transport::ImageTransport it_;
33  image_transport::Subscriber image_sub_;
34  image_transport::Publisher image_pub_;
35 
38 
40 
42 
43  int ImgCount;
44  cv_bridge::CvImagePtr cv_ptr;
45 
46 public:
47 
49  it_ (nh_)
50  {
51 
52  ImgCount = 0;
53  image_pub_ = it_.advertise ("Image_Out", 1);
54  image_sub_ =
55  it_.subscribe ("Image_In", 1, &ImageConverter::imageCb, this);
56 
57  }
58 
60  {
61 
62  }
63 
64  void imageCb (const sensor_msgs::ImageConstPtr & msg)
65  {
66 
67 
68 
69 
70  try
71  {
72 
73  cv_ptr = cv_bridge::toCvCopy (msg, "rgb8");
74 
75  cv_ptr->image.convertTo (cv_ptr->image, CV_8UC1);
76 
77  }
78  catch (cv_bridge::Exception & e)
79  {
80  ROS_ERROR ("cv_bridge exception: %s", e.what ());
81  return;
82  }
83  Mat Img = cv_ptr->image;
84 
85  if (Img.rows == 0)
86  return;
87 
88  // ROS_INFO ("Image nr %d\n", ImgCount++);
89 
90  Mat MergedChannels (Img.rows, Img.cols, CV_64FC (CHANNELNR));
91 
93 
94 
95  cvtColor (Img, Img, CV_BGR2RGB, 0);
96 
97  cvtColor (Img, GrayImg, CV_RGB2GRAY, 0);
98 
99  features.clear ();
100 
101  Sobel (GrayImg, xsobel, CV_32FC1, 1, 0, 3, 1, 0, BORDER_DEFAULT);
102  Sobel (GrayImg, ysobel, CV_32FC1, 0, 1, 3, 1, 0, BORDER_DEFAULT);
103 
105 
107 
109 
110 
111 
112  cvtColor (Img, GrayImg, CV_RGB2GRAY, 0);
114 
115 
116  cv_ptr->image = BinVect[5];
117 
118 
119  sensor_msgs::ImagePtr msg_out = cv_ptr->toImageMsg ();
120  msg_out->encoding = "32FC1";
121  msg_out->header.frame_id = "Image_Out";
122  msg_out->header.stamp = ros::Time::now ();
123 
124 
125  image_pub_.publish (msg_out);
126 
127 
128  }
129 
130 };
131 
132 int main (int argc, char **argv)
133 {
134  ros::init (argc, argv, "image_converter");
135  ImageConverter ic;
136  ros::spin ();
137  return 0;
138 }
#define CHANNELNR
Definition: peddetect.h:47
ros::NodeHandle nh_
vector< Mat > MatVector
Definition: peddetect.h:89
vector< vec10d > d10Vector
Definition: peddetect.h:91
MatVector LUVcolourchannels(Mat Img)
Definition: pedfuncs.cpp:136
image_transport::Publisher image_pub_
int main(int argc, char **argv)
cv_bridge::CvImagePtr cv_ptr
MatVector OrientedGradientsDiagram(Mat GradMag, Mat xsobel, Mat ysobel)
Definition: pedfuncs.cpp:66
void imageCb(const sensor_msgs::ImageConstPtr &msg)
image_transport::ImageTransport it_
Mat GradientMagnitude(Mat src)
Definition: pedfuncs.cpp:30
image_transport::Subscriber image_sub_
MatVector BinVect
Definition: clientimg.cpp:39
MatVector LUVchannels
Definition: clientimg.cpp:39


pedestrian_detect
Author(s): Pedro Batista
autogenerated on Mon Mar 2 2015 01:32:33