arrow_detection.cpp
Go to the documentation of this file.
1  /**************************************************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, 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 
28  #include <iostream>
29  #include <string>
30 
31  #include <ros/ros.h>
32 
33  #include <datamatrix_detection/DatamatrixMsg.h>
34 
35  #include <image_transport/image_transport.h>
36  #include <cv_bridge/cv_bridge.h>
37  #include <sensor_msgs/image_encodings.h>
38 
39  #include <opencv2/imgproc/imgproc.hpp>
40  #include <opencv2/highgui/highgui.hpp>
41 
42  #include <dmtx.h>
43 
45  {
46  ros::NodeHandle nh_;
47  // ros::Publisher datamatrix_pub;
48 
49  image_transport::ImageTransport it_;
50  image_transport::Subscriber image_sub_;
51 
52  // std::vector<std::string> leituras;
53 
54  public:
56  : it_(nh_)
57  {
58  // Subscribe to input video feed and publish output video feed
59  image_sub_ = it_.subscribe("/camera/image_raw", 1,
61  // datamatrix_pub = nh_.advertise<datamatrix_detection::DatamatrixMsg>("datamatrix_detection/datamatrix_msg",1);
62  }
63 
65  {
66  // uint total = leituras.size();
67  // std::cout << std::endl;
68  // std::cout << "Foram lidas: " << total << " DataMatrix" << std::endl;
69  // int error = 0;
70  // uint j;
71  // for ( j=0; j < leituras.size(); j++)
72  // {
73  // if (leituras[j] != "111222") error++;
74  //
75  // }
76  //
77  // std::cout << "Das quais: " << error << " foram lidas erradamente" << std::endl;
78  // std::cout << "Success rate: " << ((total - error)/static_cast<double>(total))*100. << " %" << std::endl;
79  // std::cout << std::endl;
80  }
81 
82  void imageCallback(const sensor_msgs::ImageConstPtr& msg)
83  {
84  cv_bridge::CvImagePtr cv_ptr;
85  try
86  {
87  cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
88  }
89  catch (cv_bridge::Exception& e)
90  {
91  ROS_ERROR("cv_bridge exception: %s", e.what());
92  return;
93  }
94  /*
95  * DatamatrixDecode(cv_ptr->image,cv_ptr->header);*/
96 
97 
98  // Update GUI Window
99  cv::imshow("Image", cv_ptr->image);
100  cv::waitKey(3);
101 
102  }
103 
104 
105  };
106 
107  int main(int argc, char** argv)
108  {
109  ros::init(argc, argv, "datamatrix_detection");
110  ImageConverter ic;
111  ros::spin();
112  return 0;
113  }
114 
115 
116 
117 
118  /**************************************************************************************************
119  Software License Agreement (BSD License)
120 
121  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
122  All rights reserved.
123 
124  Redistribution and use in source and binary forms, with or without modification, are permitted
125  provided that the following conditions are met:
126 
127  *Redistributions of source code must retain the above copyright notice, this list of
128  conditions and the following disclaimer.
129  *Redistributions in binary form must reproduce the above copyright notice, this list of
130  conditions and the following disclaimer in the documentation and/or other materials provided
131  with the distribution.
132  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
133  endorse or promote products derived from this software without specific prior written permission.
134 
135  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
136  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
137  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
138  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
139  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
140  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
141  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
142  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
143  ***************************************************************************************************/
144 
145 //c++
146 // #include <stdio.h>
147 // #include <iostream>
148 
150 //#include <visp/vpPixelMeterConversion.h>
151 //#include <visp/vp1394CMUGrabber.h>
152 //#include <visp/vp1394TwoGrabber.h>
153 //#include <visp/vpDisplayGDI.h>
154 //#include <visp/vpDisplayX.h>
155 //#include <visp/vpDot2.h>
156 //#include <visp/vpPose.h>
157 //#include <visp/vpConfig.h>
158 //#include <visp/vpImage.h>
159 //#include <visp/vpRGBa.h>
160 
162 //#include <visp/vpImageIo.h>
163 //#include <visp/vpImageConvert.h>
164 
166 //#include <arrow_detection/findArrow.h>
167 
169 //#include <ros/ros.h>
170 //#include <std_msgs/String.h>
171 
172 //#include <sstream>
173 //#include <unistd.h>
174 //#include <iostream>
175 //#include <cmath>
176 
177 //#include <sys/types.h>
178 //#include <unistd.h>
179 //#include <stdlib.h>
180 
181 //#include <geometry_msgs/Point.h>
182 
183 
184 //void wait_lum_set(vpImage<unsigned char> &I_grey,
185 //#if defined(VISP_HAVE_DC1394_2)
186  //vp1394TwoGrabber &g//THIS, is the one that is called!!!
187 //#elif defined(VISP_HAVE_CMU1394)
188  //vp1394CMUGrabber g
189 
190 //#endif
191 //)
192 //{
193  //std::cout << "**PLEASE SET THE CAMERA LUMINIOSITY!! ***" << std::endl;
207 //}
208 
210 // int main(int argc, char** argv)
211 // {
212 
214  //ros::init( argc, argv, "find_arrow_node" );
215 
216  //ros::NodeHandle n("~");
217 
219  //ros::Publisher pub_state= n.advertise< geometry_msgs::Point >( "/find_arrow_state", 1000 );
220 
221  //ros::Rate r(20); // 50 hz
222 
223  //cv::VideoCapture cap(0);// open the first avialable video camera (no. 0?)
224 
225  //const int min_servo_pos=600;
226 
227  //namedWindow("frame", CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
228 
229  //double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
230  //double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
232 
233  //#if (defined(VISP_HAVE_DC1394_2) || defined(VISP_HAVE_CMU1394))
234  //vpImage<unsigned char> I; // Create a gray level image container
235 
236 //#if defined(VISP_HAVE_DC1394_2)
237  //vp1394TwoGrabber g(false);
238 //#elif defined(VISP_HAVE_CMU1394)
239  //vp1394CMUGrabber g;
240 //#endif
241  //g.open(I);
242  //g.acquire(I);
243 
244 //#if defined(VISP_HAVE_X11)
245  //vpDisplayX d(I, 0, 0, "Camera view");
246 //#elif defined(VISP_HAVE_GDI)
247  //vpDisplayGDI d(I, 0, 0, "Camera view");
248 //#else
249  //std::cout << "No image viewer is available..." << std::endl;
250 //#endif
251  //vpDisplay::display(I);
252  //vpDisplay::flush(I);
253 //std::cout << "teste1" << std::endl;
254  //vpDot2 blob;
255  //blob.setGraphics(true);
256  //blob.setGraphicsThickness(2);
258  //cv::Point src_centre; bool init = true; cv::Mat I_mat;
259  //std::cout << "teste2" << std::endl;
260 
261  //wait_lum_set(I,g);//set luminiosity
262  //#endif
263 
265  //geometry_msgs::Point ponto;
266  //int const start_pos_x = 1950;
267  //int const start_pos_y = 1470;
269  //ponto.x = start_pos_x; ponto.y = start_pos_y;
270 
271  //int const xcenter = 235;
272  //int const ycenter = 320;
273  //std::cout << "before loop..." << std::endl;
274 
275  //while(ros::ok())
276  //{
277  //try
278  //{
279  //if (init)
280  //{
281  //ponto.x = 1; ponto.y = 0; ponto.z = 0;
282  //pub_state.publish( ponto );
283  //std::cout << "arrow lost!" << std::endl;
284  //vpImageConvert::convert(I,I_mat);
285  //vpTime::wait(10);
286 
287  //findArrow::find_arrow(I_mat,src_centre);
288  //if (findArrow::found_new_point == true)
289  //{
290  //blob.initTracking(I,vpImagePoint(src_centre.y, src_centre.x));//cesar
291  //init = false;
292  //}
294  //g.acquire(I);
295  //vpDisplay::display(I);
296  //vpDisplay::flush(I);
297  //}
298  //else
299  //{
300  //std::cout << "arrow FOUND!" << std::endl;
301  //vpImagePoint center(blob.getCog());
302  //std::cout << "i: " << (int) center.get_i() << " j:" << (int) center.get_j() << std::endl;
303 
312 
313  //int dif_x = (((int) center.get_i()) - xcenter);
314  //int dif_y = (((int) center.get_j()) - ycenter);
315  //std::cout << "dif_x" << dif_x << "dif_y" << dif_y << std::endl;
316 
317  //if(dif_x > 0 && dif_y > 0)
318  //{
319  //ponto.x = 1;
320  //}
321  //if(dif_x > 0 && dif_y < 0)
322  //{
323  //ponto.x = 2;
324  //}
325  //if(dif_x < 0 && dif_y > 0)
326  //{
327  //ponto.x = 3;
328  //}
329  //if(dif_x < 0 && dif_y < 0)
330  //{
331  //ponto.x = 4;
332  //}
333 
335  //dif_y < 0 ? dif_y = -dif_y : dif_x = dif_x;
336  //dif_x < 0 ? dif_x = -dif_x : dif_x = dif_x;
337 
338 
339  //ponto.y = ((int) dif_x) / 15;
340  //ponto.z = ((int) dif_y) / 15;
341 
342  //std::cout << "x: " << ponto.x << "y:" << ponto.y << "vel" << ponto.z << std::endl;
345  //pub_state.publish( ponto );
346 
348 
349  //g.acquire(I); // Acquire an image
350  //vpDisplay::display(I);
351  //blob.track(I);
352  //vpDisplay::flush(I);
353  //if (vpDisplay::getClick(I, false))
354  //break;
355  //}
356  //}
357  //catch(vpException e)
358  //{
359  //std::cout << "Catch an exception: " << e << std::endl;
360  //init=true;
361  //}
362  //ros::spinOnce ( );
363  //r.sleep(); //rosrate (50Hz)
364  //}
365 
366  //std::cout << " Exit successful" << std::endl;
367  //return 0;
368 
369 
370 // }
ros::NodeHandle nh_
int main(int argc, char **argv)
void imageCallback(const sensor_msgs::ImageConstPtr &msg)
image_transport::ImageTransport it_
image_transport::Subscriber image_sub_


arrow_detection
Author(s): César Sousa
autogenerated on Mon Mar 2 2015 01:31:21