Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCentaurus.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /** @example ExampleVideoCentaurus.cpp
27  @relates VideoSource_Centaurus
28  @ingroup g_examples
29  @ingroup g_videosource
30  @brief Example for using the videosource centaurus
31  @author MIP
32 */
33 
34 #include <VideoSource/VideoSource_Centaurus.hh>
35 #include <Base/Image/ImageIO.hh>
36 
37 using namespace std;
38 using namespace BIAS;
39 
40 int main(int argc, char** argv)
41 {
42 
43  int res=-1;
44  Image<unsigned char> image1;
45  image1.Init(1920, 1080, 2, ImageBase::ST_unsignedchar);
46  image1.SetColorModel(ImageBase::CM_YUYV422);
47 
48  Image<unsigned char> image2;
49  image2.Init(1920, 1080, 2, ImageBase::ST_unsignedchar);
50  image2.SetColorModel(ImageBase::CM_YUYV422);
51 
52 
53  char setup[] = "PCI,card=0";
54 // char setup[] = "";
55  sv_handle* cam_handleP1_= NULL;
56 
57  cam_handleP1_ = sv_open(&setup[0]);
58 
59 
60 
61  if (cam_handleP1_==NULL) {
62  cout << "failed to open cam, camera handle = " << cam_handleP1_ << endl;
63  return -1;
64  } else {
65  cout << "opened cam " << cam_handleP1_ << endl;
66  }
67 
68 
69 
70 
71  // Configure single-link input B (jack ID 3)
72  int mode = SV_MODE_COLOR_YUV422_YUYV
73  | SV_MODE_SMPTE274_25sF | SV_MODE_STORAGE_FRAME;
74 
75 
76  //-------------------------------------- A
77  res = sv_jack_option_set(cam_handleP1_, 1, SV_OPTION_VIDEOMODE, mode);
78  if (res != SV_OK) {
79  BIASERR(sv_geterrortext(res) << endl);
80  }
81  res = sv_jack_option_set(cam_handleP1_, 1, SV_OPTION_IOMODE, SV_IOMODE_YUV422);
82  if (res != SV_OK) {
83  BIASERR(sv_geterrortext(res) << endl);
84  }
85 
86  res = sv_option_set(cam_handleP1_,SV_OPTION_MULTICHANNEL,SV_MULTICHANNEL_INPUT);
87  if (res != SV_OK) {
88  BIASERR(sv_geterrortext(res) << endl);
89  }
90 
91  //--------------------------------------- B
92 
93 
94  res = sv_jack_option_set(cam_handleP1_, 3, SV_OPTION_VIDEOMODE, mode);
95  if (res != SV_OK) {
96  BIASERR(sv_geterrortext(res) << endl);
97  }
98  res = sv_jack_option_set(cam_handleP1_, 3, SV_OPTION_IOMODE, SV_IOMODE_YUV422);
99  if (res != SV_OK) {
100  BIASERR(sv_geterrortext(res) << endl);
101  }
102 
103 
104 // res = sv_videomode(cam_handleP1_, mode);
105 // if (res != SV_OK) {
106 // BIASERR(sv_geterrortext(res) << endl);
107 // }
108 
109 
110 
111 // int mode = SV_MODE_COLOR_YUV422_YUYV
112 // | SV_MODE_SMPTE274_25sF | SV_MODE_STORAGE_FRAME;
113 
114 // res = sv_jack_option_set(cam_handleP1_,port,SV_OPTION_VIDEOMODE,mode);
115 // if (res != SV_OK) {
116 // BIASERR("sv_jack_option_set : " << sv_geterrortext(res) << endl);
117 // }
118 
119 
120 
121  sv_fifo* inputFifoP1_;
122  res = sv_fifo_init(cam_handleP1_, &inputFifoP1_,1, 0, 1,
123  SV_FIFO_FLAG_VIDEOONLY, 0);
124  if (res != SV_OK) {
125  BIASERR(sv_geterrortext(res) << endl);
126  }
127 
128 
129  sv_fifo* inputFifoP2_;
130  res = sv_fifo_init(cam_handleP1_, &inputFifoP2_,3, 0, 1,
131  SV_FIFO_FLAG_VIDEOONLY, 0);
132  if (res != SV_OK) {
133  BIASERR(sv_geterrortext(res) << endl);
134  }
135 
136 
137  //-----------------------------
138  res = sv_fifo_start(cam_handleP1_, inputFifoP1_);
139  if (res != SV_OK) {
140  BIASERR(sv_geterrortext(res) << endl);
141  }
142 
143  res = sv_fifo_start(cam_handleP1_, inputFifoP2_);
144  if (res != SV_OK) {
145  BIASERR(sv_geterrortext(res) << endl);
146  }
147 
148  int flags = 0;
149  flags |= SV_FIFO_FLAG_VSYNCWAIT;
150  flags |= SV_FIFO_FLAG_FLUSH;
151 
152 
153  //--------------------------- A
154  sv_fifo_buffer* sv_buffer1;
155  res = sv_fifo_getbuffer(cam_handleP1_, inputFifoP1_, &sv_buffer1,
156  NULL, flags);
157  if (res != SV_OK) {
158  BIASERR(sv_geterrortext(res) << endl);
159 
160  }
161 
162  sv_buffer1->dma.addr = (char*) image1.GetImageData();
163  sv_buffer1->dma.size = image1.GetWidth() * image1.GetHeight()
164  * image1.GetChannelCount();
165 
166  res = sv_fifo_putbuffer(cam_handleP1_, inputFifoP1_, sv_buffer1, NULL);
167  if (res != SV_OK) {
168  BIASERR(sv_geterrortext(res) << endl);
169  }
170 
171  // -------------------------- B
172  sv_fifo_buffer* sv_buffer2;
173  res = sv_fifo_getbuffer(cam_handleP1_, inputFifoP2_, &sv_buffer2,
174  NULL, flags);
175  if (res != SV_OK) {
176  BIASERR(sv_geterrortext(res) << endl);
177 
178  }
179 
180  sv_buffer2->dma.addr = (char*) image2.GetImageData();
181  sv_buffer2->dma.size = image2.GetWidth() * image2.GetHeight()
182  * image2.GetChannelCount();
183 
184  res = sv_fifo_putbuffer(cam_handleP1_, inputFifoP2_, sv_buffer2, NULL);
185  if (res != SV_OK) {
186  BIASERR(sv_geterrortext(res) << endl);
187  }
188 
189 //// VideoSource_Centaurus vc;
190 //// int res = vc.OpenDevice(setup, SV_OPENPROGRAM_DEFAULT, SV_OPENTYPE_DEFAULT, 0, 0);
191 //// cout << "res = " << res << endl;
192 
193 //// res = vc.SetVideoMode();
194 //// res = vc.InitFiFo();
195 //// Camera<unsigned char> image;
196 //// vc.InitImage(image);
197 
198 //// vc.GrabSingle(image);
199 
200  ImageIO::Save("testGrab1.mip",image1);
201  cout << "saved testGrab1.mip" << endl;
202 
203  ImageIO::Save("testGrab2.mip",image2);
204  cout << "saved testGrab2.mip" << endl;
205 
206  res = sv_close(cam_handleP1_);
207  if (res != SV_OK) {
208  BIASERR("sv_close : " << sv_geterrortext(res) << endl);
209  }
210 
211  return 0;
212 }
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
unsigned int GetWidth() const
Definition: ImageBase.hh:312
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
unsigned int GetHeight() const
Definition: ImageBase.hh:319
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137