source: UH/SAMGAR/SAMGAR LIB/TesterFiles/SamgarSendImage.cpp @ 121

Revision 121, 4.4 KB checked in by KDucasse, 10 years ago (diff)

Folder and files for the to compile samgar modules

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
13
14// To use samgar you only need to attach the SamgarLib and the SamgarMainClass header
15#include "cv.h"
16#include "highgui.h"
17#include <SamgarMainClass.h>
18
19
20int main() {
21
22        // Creates a module with a name , catagory , sub catagory , typeofmodule
23        SamgarModule MyFirstTest("Module1","behaviour","happy","Cont"); // Cant have spaces or underscores
24        // then we setup the image port
25        MyFirstTest.SetupImagePort("VideoOut");
26
27    SamgarModule MyFirstTest2("Module2","behaviour","happy","Cont"); // Cant have spaces or underscores
28        MyFirstTest2.SetupImagePort("VideoIn");
29
30        // can use samgarkey to connect ports but for this demo we'll ignore it and do it manually (this shouldnt be done)
31        Network::connect("/Port_Module1_VideoOut_Yarp","/Port_Module2_VideoIn_Yarp","udp");
32        Network::connect("/Port_Module2_VideoIn_Yarp","/Port_Module1_VideoOut_Yarp","udp");
33
34 // OCV get a device
35  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
36  // OCV make sure its there
37  if( !capture ) {fprintf( stderr, "ERROR: capture is NULL \n" );getchar();return -1;}
38
39 
40  cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
41  cvNamedWindow( "copy", CV_WINDOW_AUTOSIZE );
42
43  while( 1 )
44  {
45    IplImage* frame = cvQueryFrame( capture );
46    if( !frame ){fprintf( stderr, "ERROR: frame is null...\n" );getchar();break;}
47       
48    cvShowImage( "original", frame );
49        // send the frame
50        MyFirstTest.SendPictureOCVNative(frame);
51        // recive the frame
52        IplImage *frame2 = MyFirstTest2.RecivePictureOCVNative();
53
54        if(frame2!=false) // if there is no image available (one hasn't been sent) then the image will be false
55        {
56    cvShowImage( "copy", frame2 ); // if its not false then display it.
57        }
58
59    if( (cvWaitKey(10) & 255) == 27 ) break;
60  }
61
62
63  cvReleaseCapture( &capture );
64  cvDestroyWindow( "original" );
65  return 0;
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
125
126
127
128
129/*
130
131#include "cv.h"
132#include "highgui.h"
133
134
135#include <stdio.h>
136#include <SamgarMainClass.h>
137using namespace std;
138
139
140using namespace yarp::sig::draw;
141
142int main()
143{
144SamgarModule MyFirstTest1("Module1","behaviour","happy","Interupt"); // Cant have spaces or underscores
145MyFirstTest1.SetupImagePort("VideoOut");
146
147SamgarModule MyFirstTest2("Module2","behaviour","happy","Interupt"); // Cant have spaces or underscores
148MyFirstTest2.SetupImagePort("VideoIn");
149
150Network::connect("/Port_Module2_VideoIn_OCV","/Port_Module1_VideoOut_OCV","udp");
151Network::connect("/Port_Module1_VideoOut_OCV","/Port_Module2_VideoIn_OCV","udp");
152 ImageOf<PixelBgr> yarpImage;
153                 yarpImage.resize(300,200);
154                 addCircle(yarpImage,PixelBgr(255,0,0),
155         yarpImage.width()/2,yarpImage.height()/2,
156         yarpImage.height()/4);
157
158
159while(1)
160        {
161        //      MyFirstTest1.SendPictureYarpNative
162
163           
164                 MyFirstTest1.SendPictureYarpNative(yarpImage);
165
166        }
167
168}
169
170
171
172/*
173
174#include "cv.h"
175#include "highgui.h"
176#include <stdio.h>
177
178
179
180//#include <SamgarMainClass.h>
181//using namespace std;
182
183int main (void)
184{
185//SamgarModule MyFirstTest("Module1","behaviour","happy","Interupt"); // Cant have spaces or underscores
186//MyFirstTest.AddPort("output1");
187//MyFirstTest.AddPort("output2");
188//MyFirstTest.AddPort("output3");
189//MyFirstTest.AddPort("output4");
190//MyFirstTest.AddPort("output5");
191//MyFirstTest.AddPort("output6");
192//MyFirstTest.AddPort("output7");
193//Network::connect("/Port_Module1_output7","/Port_Module2_output7");
194//Network::connect("/Port_Module2_output7","/Port_Module1_output7");
195
196//static double xx = 1;
197//string yy;
198
199  cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
200
201  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
202  if( !capture ) {   fprintf( stderr, "ERROR: capture is NULL \n" ); getchar();return -1;}
203
204 // MyFirstTest.SetupImagePort("VideoOut");
205
206
207 
208
209
210while(1)
211{
212    IplImage* frame = cvQueryFrame( capture );
213    if( !frame ) {fprintf( stderr, "ERROR: frame is null...\n" );getchar();break;}
214        cvShowImage( "mywindow", frame);
215}
216
217
218//sleep(10);
219return 0;
220}*/
Note: See TracBrowser for help on using the repository browser.