iCub-main
main.cpp
Go to the documentation of this file.
1 
64 #include <yarp/sig/Image.h>
65 #include <yarp/os/Network.h>
66 #include <yarp/os/Port.h>
67 #include <yarp/os/BufferedPort.h>
68 
69 #include <iostream>
70 #include <math.h>
71 
72 using namespace yarp::os;
73 using namespace yarp::sig;
74 
75 const int scale = 1;
76 void printFrame(int h, int w, int c);
77 
78 void merge(const ImageOf<PixelRgb> &imgR, const ImageOf<PixelRgb> &imgL, ImageOf<PixelRgb> &out)
79 {
80  if (out.width()!=imgR.width()/scale)
81  out.resize(imgR.width()/scale, imgR.height()/scale);
82 
83  int rr=0;
84  for(int r=0; r<out.height(); r++)
85  {
86  const unsigned char *tmpR=imgR.getRow(rr);
87  const unsigned char *tmpL=imgL.getRow(rr);
88  unsigned char *tmpO=out.getRow(r);
89 
90  for(int c=0; c<out.width(); c++)
91  {
92  tmpO[0]=(unsigned char) (1/3.0*(tmpL[0]+tmpL[1]+tmpL[2]));
93  tmpO[1]=(unsigned char) (1/3.0*(tmpR[0]+tmpR[1]+tmpR[2]));
94 
95  tmpO+=3;
96  tmpL+=(3*scale);
97  tmpR+=(3*scale);
98  }
99 
100  rr+=scale;
101  }
102 }
103 
104 int main(int argc, char *argv[])
105 {
106  Network yarp;
107  int c=0;
108 
109  BufferedPort<ImageOf<PixelRgb> > right;
110  BufferedPort<ImageOf<PixelRgb> > left;
111 
112  BufferedPort<ImageOf<PixelRgb> > out;
113 
114  right.open("/teststereomatch/right");
115  left.open("/teststereomatch/left");
116 
117  out.open("/teststereomatch/o");
118 
119  while(true)
120  {
121  ImageOf< PixelRgb> *imgR=right.read(true);
122  ImageOf< PixelRgb> *imgL=left.read(true);
123 
124  ImageOf< PixelRgb> &outImg=out.prepare();
125 
126  if (imgR!=0 && imgL!=0)
127  {
128  merge(*imgR, *imgL, outImg);
129 
130  out.write();
131  c++;
132  }
133  printFrame(outImg.height(), outImg.width(), c);
134  }
135  return 0;
136 }
137 
138 void printFrame(int h, int w, int c)
139 {
140  if (c%500 == 0)
141  printf("Frame #%d %dx%d \n", c, h, w);
142 }
out
Definition: sine.m:8
Copyright (C) 2008 RobotCub Consortium.
void printFrame(int h, int w, int c)
Definition: main.cpp:135
void merge(const ImageOf< PixelRgb > &imgR, const ImageOf< PixelRgb > &imgL, ImageOf< PixelRgb > &out, size_t start_lx, size_t start_ly, size_t start_rx, size_t start_ry, double alpha1, double alpha2)
Definition: main.cpp:17
const int scale
Definition: main.cpp:75
int main(int argc, char *argv[])
Definition: main.cpp:31