source: libs/SamgarWRUTed/tags/1.0/libSamgar/examples/SamgarSendImage.cpp @ 447

Revision 447, 3.8 KB checked in by lmalek, 10 years ago (diff)

tree structure reorganization

Line 
1
2/***********************************************************************
3
4Program : example sending images with SAMGAR
5Date    : 24 Aug 2009
6Author  : K Du Casse
7
8A simple program that shows how to send images with SAMGAR
9
10***********************************************************************/
11
12// To use samgar you only need to attach the SamgarLib and the
13// SamgarMainClass header
14
15#include "cv.h"
16#include "highgui.h"
17#include <Samgar.h>
18
19using namespace std;
20
21int main() {
22  Network yarp;
23  // Creates a module with a name , catagory , sub catagory , typeofmodule
24  Samgar::SamgarModule CameraSend("CameraSend","Image",
25                                  "Camera",Samgar::ModeRun);
26  // Cant have spaces or underscores
27  // then we setup the image port
28  CameraSend.SetupImagePort("VideoOut");
29  // OCV get a device
30  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
31  // OCV make sure its there
32  if( !capture ) {
33    fprintf( stderr, "ERROR: capture is NULL \n" );
34    getchar();
35    return -1;
36  }
37  cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
38
39  while( 1 ) {
40      if (CameraSend.getCurrentState() == Samgar::StateRunning)
41      {
42          IplImage* frame = cvQueryFrame( capture );
43          if( !frame )
44          {
45              fprintf( stderr, "ERROR: frame is null...\n" );
46              getchar();
47              break;
48          }
49          cvShowImage( "original", frame );
50          // send the frame
51          CameraSend.SendPictureOCVNative(frame);
52      }
53      if( (cvWaitKey(10) & 255) == 27 ) break;
54      CameraSend.SucceedFail(true,0);
55  }
56  cvReleaseCapture( &capture );
57  cvDestroyWindow( "original" );
58  return 0;
59}
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122/*
123
124#include "cv.h"
125#include "highgui.h"
126
127
128#include <stdio.h>
129#include <SamgarMainClass.h>
130using namespace std;
131
132
133using namespace yarp::sig::draw;
134
135int main()
136{
137SamgarModule MyFirstTest1("Module1","behaviour","happy","Interupt"); // Cant have spaces or underscores
138MyFirstTest1.SetupImagePort("VideoOut");
139
140SamgarModule MyFirstTest2("Module2","behaviour","happy","Interupt"); // Cant have spaces or underscores
141MyFirstTest2.SetupImagePort("VideoIn");
142
143Network::connect("/Port_Module2_VideoIn_OCV","/Port_Module1_VideoOut_OCV","udp");
144Network::connect("/Port_Module1_VideoOut_OCV","/Port_Module2_VideoIn_OCV","udp");
145 ImageOf<PixelBgr> yarpImage;
146                 yarpImage.resize(300,200);
147                 addCircle(yarpImage,PixelBgr(255,0,0),
148         yarpImage.width()/2,yarpImage.height()/2,
149         yarpImage.height()/4);
150
151
152while(1)
153        {
154        //      MyFirstTest1.SendPictureYarpNative
155
156           
157                 MyFirstTest1.SendPictureYarpNative(yarpImage);
158
159        }
160
161}
162
163
164
165/*
166
167#include "cv.h"
168#include "highgui.h"
169#include <stdio.h>
170
171
172
173//#include <SamgarMainClass.h>
174//using namespace std;
175
176int main (void)
177{
178//SamgarModule MyFirstTest("Module1","behaviour","happy","Interupt"); // Cant have spaces or underscores
179//MyFirstTest.AddPort("output1");
180//MyFirstTest.AddPort("output2");
181//MyFirstTest.AddPort("output3");
182//MyFirstTest.AddPort("output4");
183//MyFirstTest.AddPort("output5");
184//MyFirstTest.AddPort("output6");
185//MyFirstTest.AddPort("output7");
186//Network::connect("/Port_Module1_output7","/Port_Module2_output7");
187//Network::connect("/Port_Module2_output7","/Port_Module1_output7");
188
189//static double xx = 1;
190//string yy;
191
192  cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
193
194  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
195  if( !capture ) {   fprintf( stderr, "ERROR: capture is NULL \n" ); getchar();return -1;}
196
197 // MyFirstTest.SetupImagePort("VideoOut");
198
199
200 
201
202
203while(1)
204{
205    IplImage* frame = cvQueryFrame( capture );
206    if( !frame ) {fprintf( stderr, "ERROR: frame is null...\n" );getchar();break;}
207        cvShowImage( "mywindow", frame);
208}
209
210
211//sleep(10);
212return 0;
213}*/
214
Note: See TracBrowser for help on using the repository browser.