clientimg.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_64FC1, 1, 0, 3, 1, 0, BORDER_DEFAULT);
102  Sobel (GrayImg, ysobel, CV_64FC1, 0, 1, 3, 1, 0, BORDER_DEFAULT);
103 
105 
107 
109 
110  Mat ToBeMergedChannels[] =
111  { GradMag, BinVect[0], BinVect[1], BinVect[2], BinVect[3], BinVect[4],
112  BinVect[5], LUVchannels[0], LUVchannels[1], LUVchannels[2]
113  };
114 
115 
116  merge (ToBeMergedChannels, CHANNELNR, MergedChannels);
117 
118  integral (GradMag, integralim, CV_64F);
119 
120  integral (MergedChannels, IntegralChns, CV_64FC (CHANNELNR));
121 
122 
123  CvRect region;
124  region.x = 0;
125  region.y = 0;
126  region.width = 15;
127  region.height = 90;
128 
130 
131  cout<<features.size()<<endl;
132 
133  cvtColor (Img, GrayImg, CV_RGB2GRAY, 0);
135 
136 
137  cv_ptr->image = BinVect[0];
138 
139 
140 
141  sensor_msgs::ImagePtr msg_out = cv_ptr->toImageMsg ();
142  msg_out->encoding = "64FC1";
143  msg_out->header.frame_id = "Image_Out";
144  msg_out->header.stamp = ros::Time::now ();
145 
146 
147  image_pub_.publish (msg_out);
148 
149 
150  }
151 
152 };
153 
154 int main (int argc, char **argv)
155 {
156  ros::init (argc, argv, "image_converter");
157  ImageConverter ic;
158  ros::spin ();
159  return 0;
160 }
#define CHANNELNR
Definition: peddetect.h:47
ros::NodeHandle nh_
vector< Mat > MatVector
Definition: peddetect.h:89
int main(int argc, char **argv)
Definition: clientimg.cpp:154
void GetChnFtrsOverImage(Mat IntegralChannels, CvRect &region, vector< float > &features, FtrVecParams2 Params, PedRoiVec &PedRect, CvBoost &boost_classifier)
Definition: pedfuncs.cpp:388
vector< vec10d > d10Vector
Definition: peddetect.h:91
d10Vector features
Definition: clientimg.cpp:41
MatVector LUVcolourchannels(Mat Img)
Definition: pedfuncs.cpp:136
image_transport::Publisher image_pub_
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