segmentation
All Data Structures Namespaces Files Functions Variables Modules Pages
testGbsClient.cpp
1 // Author: Elena Ceseracciu, RBCS-Istituto Italiano di Tecnologia - 2012
2 
3 #include <string>
4 #include <iostream>
5 #include <yarp/os/Network.h>
6 #include <yarp/os/BufferedPort.h>
7 #include <yarp/os/Port.h>
8 
9 #include "SegmModule.h"
10 
11 using namespace yarp::os;
12 using namespace yarp::sig;
13 
14 int main(int argc, char *argv[]) {
15 
16  Network yarp;
17 
18  if (!yarp.checkNetwork())
19  return -1;
20 
21 
22  Port clientPort;
23  Port fixationPort;
24  BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > maskPort;
25 
26 
27  ResourceFinder rf;
28  rf.configure(argc, argv);
29  std::string name="testGbsClient";
30  if (rf.check("name"))
31  {
32  name=rf.find("name").asString();
33  }
34 
35  std::string slash="/";
36  clientPort.open(slash+name+slash +"rpc:o");
37  fixationPort.open(slash+name+slash +"interestPoint:i");
38  maskPort.open(slash+name+slash +"mask:o");
39 
40 
42  segmIf.yarp().attachAsClient(clientPort);
43 
44 
45  while(true)
46  {
47  Bottle fixIn;
48  fixIn.clear();
49  fixationPort.read(fixIn);
50 
51  if (fixIn.size()>1)
52  {
53  double fix_x = fixIn.get(0).asFloat64();
54  double fix_y = fixIn.get(1).asFloat64();
55 // double cropSizeWidth = fixIn.get(2).asInt32();
56 // double cropSizeHeight = fixIn.get(3).asInt32();
57  std::vector<Pixel> pixelList=segmIf.get_component_around(Pixel(fix_x, fix_y));
58  std::cout<<"asked server"<<std::endl;
59  yarp::sig::ImageOf< yarp::sig::PixelRgb > &img=maskPort.prepare();
60  img.resize(320, 240);
61  img.zero();
62  for(std::vector<Pixel>::const_iterator pixIt=pixelList.begin(); pixIt!=pixelList.end(); ++pixIt)
63  {
64  img.pixel(pixIt->x, pixIt->y) = yarp::sig::PixelRgb(255, 255, 255);
65  }
66  maskPort.write();
67 
68  }
69  }
70  return 0;
71 }
Pixel position in the image frame.
Definition: Pixel.h:28
Interface for module that performs graph-based segmentation.
virtual std::vector< Pixel > get_component_around(const Pixel &objCenter)
Get the list of pixels corresponding to the component to which a given pixel belongs.