Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
showdcam.cpp
1 #include <bias_config.h>
2 #include <Base/Common/W32Compat.hh> // sprintf wrn
3 #include <VideoSource/VideoSource_Base.hh>
4 #include <VideoSource/VideoSource_DCAM.hh>
5 
6 #include <Base/Image/ImageIO.hh>
7 #include <Base/Image/ImageConvert.hh>
8 #include <Image/Camera.hh>
9 #include <Gui/ImageCanvas.hh>
10 #include <Gui/ConsoleRedirectIO.hh>
11 
12 
13 using namespace BIAS;
14 using namespace std;
15 
16 bool done = false;
17 bool save = false;
18 
19 #define GUI
20 #ifdef GUI
21 
22 /** \cond HIDDEN_SYMBOLS */
23 class MyApp : public wxApp
24 {
25  virtual bool OnInit();
26 };
27 
28 class MyFrame: public wxFrame
29 {
30 public:
31 
32  MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
33 
34  void OnQuit(wxCommandEvent& event);
35  void OnTimer(wxTimerEvent& event);
36 
37  DECLARE_EVENT_TABLE()
38 protected:
39  wxButton *QuitButton_, *WhiteBalanceButton_;
40  ImageCanvas *ic_;
41  wxTimer Timer_;
42  VideoSource_DCAM cam;
43  Camera<unsigned char> pic,rgb;
44  const string camfile;
45  int framecount;
46 };
47 
48 
49 enum
50 {
51  ID_Quit = 1,
53  ID_TIMER = 1001
54 };
55 
56 
57 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
58  EVT_MENU(ID_Quit, MyFrame::OnQuit)
59  EVT_BUTTON(ID_BUTTON_QUIT, MyFrame::OnQuit)
60  EVT_TIMER(ID_TIMER, MyFrame::OnTimer)
61 END_EVENT_TABLE()
62 
63 IMPLEMENT_APP(MyApp)
64 
65 bool MyApp::OnInit()
66 {
67  // ConsoleRedirectIO();
68  // int channel = 0;
69  // int res = ioctl(open("/dev/video1394-0",O_RDONLY),VIDEO1394_IOC_UNLISTEN_CHANNEL,&channel)
70  //cout <<res;
71  MyFrame *frame =
72  new MyFrame( wxT("MDCam2ShmWx"), wxPoint(50,50), wxSize(800,600) );
73  SetTopWindow(frame);
74 
75  return TRUE;
76 }
77 
78 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
79 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
80 {
81  wxMenu *menuFile = new wxMenu;
82  menuFile->Append( ID_Quit, wxT("E&xit") );
83 
84  wxMenuBar *menuBar = new wxMenuBar;
85  menuBar->Append( menuFile, wxT("&File") );
86 
87  SetMenuBar( menuBar );
88  wxStatusBar* s = CreateStatusBar();
89  SetStatusText( wxT("") );
90 
91  wxSizer *Sizer = new wxBoxSizer( wxHORIZONTAL );
92 
93 
94  ic_ = new ImageCanvas(this,s,0);
95  ic_->SetSize(1024,768);
96  Sizer->Add(ic_,1, wxEXPAND |wxALL , 5);
97  rgb.Init(1024,768,3);
98  rgb.FillImageWithConstValue(255);
99  SetSizer( Sizer );
100 
101  Timer_.SetOwner(this, ID_TIMER);
102 
103  cam.SetDebugLevel(D_DCAM );
104  //cam.SetDebugLevelDcam(D_DCAM_F7 |D_DCAM );
105 
106  cam.SetSize(1024,768);
107  cam.SetColorModel(ImageBase::CM_UYVY422);
108  cam.SetFPS(7.5);
109  //cam.SetFormat7(0,1536,DC1394_COLOR_CODING_YUV422);
110 
111 
112  int res = cam.OpenDevice();
113  if (res!=0) {
114  cout<<"Failed to open device"<<endl;
115  exit(-1);
116  }
117 
118  cam.InitImage(pic);
119 
120  cam.PreGrab();
121 
122  framecount = 0;
123  ic_->Show(rgb,"foo");
124  SetAutoLayout(true);
125  Layout();
126  Show();
127 
128  Timer_.Start(100, true);
129 }
130 
131 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
132 {
133  Timer_.Stop();
134  biassleep(1);
135  cam.PostGrab();
136  cam.CloseDevice();
137  Destroy();
138 }
139 
140 
141 void MyFrame::OnTimer(wxTimerEvent& event)
142 {
143  cout <<"OnTimer()"<<endl;
144  cam.GrabSingle(pic);
145  framecount++;
146  ImageConvert::ToRGB(pic,rgb);
147 
148  unsigned char **ida = rgb.GetImageDataArray();
149  unsigned x = framecount % rgb.GetWidth();
150  unsigned y = framecount / rgb.GetHeight();
151  for (unsigned int c=0;c<rgb.GetChannelCount(); c++)
152  ida[y][x*rgb.GetChannelCount()+c] = 0;
153 
154  ic_->Show(rgb,"foo");
155 
156 
157 
158  // sprintf(name,"image_%04i",imgNo);
159  // BIAS::ImageIO::Save(name,rgb,ImageIO::FF_jpg);
160  // cout<<"Written image:"<<name<<" to disk"<<endl;
161  Refresh();
162 
163  Timer_.Start(20, true); // grab new images every 20 ms = resp 50 Hz
164 }
165 
166 
167 
168 #else //ifdef GUI
169 
170 int main(int argc,char *argv[])
171 {
172  cout <<"Non-gui mode"<<endl;
173 
174  VideoSource_DCAM cam;
176  // cam.SetModeAndFramerate(DC1394_VIDEO_MODE_1024x768_YUV422,7.5);
177  int res = cam.OpenDevice();
178  if (res<0) return 1;
179  cam.InitImage(img);
180  cam.PreGrab();
181  for (unsigned int i=0;i<10;i++) {
182  cout <<"Awaiting image"<<endl;
183  cam.GrabSingle(img);
184  cout <<"Got one image"<<endl;
185  }
186  cam.PostGrab();
187  cam.CloseDevice();
188 
189  return 0;
190 }
191 /** \endcond */
192 #endif
virtual int InitImage(BIAS::ImageBase &Image)
int GrabSingle(BIAS::Camera< unsigned char > &image)
Select the port (bus-id) to use, only valid before OpenDevice()
extends the Image by MetaData support (e.g.
Definition: Camera.hh:74
display image in wx application, provides zoom and investigation functionality
Definition: ImageCanvas.hh:38
This class VideoSource_DCAM implements access to IEEE1394 (Firewire, iLink) cameras following the DCa...
int OpenDevice()
Opens a dc1394 device.
UYVY422, 2 channels, full luminance Y, subsampled half U,V inverse order.
Definition: ImageBase.hh:134
int CloseDevice()
closes a camera device and cleans up
int PostGrab()
stops iso transmission of a camera.
int PreGrab()
initializes the iso transmission of a camera.
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.