Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biaspmdcam2shm.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 #include <iostream>
26 #include <VideoSource/VideoSource_PMD.hh>
27 #include <Utils/Param.hh>
28 #include <fstream>
29 #include <VideoSource/VideoShMFeederPMD.hh>
30 #include <signal.h>
31 #include "wx/wx.h"
32 #include <Gui/StringConv.hh>
33 #include <Base/Debug/Exception.hh>
34 
35 using namespace BIAS;
36 using namespace std;
37 
38 
39 /** \cond HIDDEN_SYMBOLS
40  @file
41  @ingroup g_tools
42  @brief Opens a PMD camera and writes images to a shared memory object, see biaspmdcam2shm.cpp
43  @author MIP
44 */
45 class MyApp : public wxApp
46 {
47  virtual bool OnInit();
48 };
49 
50 
51 class MyFrame: public wxFrame
52 {
53 public:
54 
55  MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
56 
57  void OnQuit(wxCommandEvent& event);
58  void OnAbout(wxCommandEvent& event);
59  void OnFrequency(wxScrollEvent& event);
60  void OnIntegrationTime(wxScrollEvent& event);
61  void OnTimer(wxTimerEvent& event);
62  void OnGetFrequency(wxCommandEvent& event);
63  void OnGetIntegrationTime(wxCommandEvent& event);
64 
65  DECLARE_EVENT_TABLE()
66 protected:
67  wxButton *QuitButton_;
68  wxSlider *SliderFrequency_;
69  wxSlider *SliderIntegrationTime_;
70  wxTimer Timer_;
71 
72  VideoSource_PMD Cam_;
73  Camera<unsigned char> GrabImage_;
74  Camera<float> DepthImage_;
75  Camera<float> ModCoeffImage_;
76  std::string ShmName_;
77  const string ShmPrefix_;
78 
79  BIAS::VideoShMFeederPMD* pShmFeeder_;
80  int framecount_;
81 };
82 
83 
84 enum
85 {
86  ID_Quit = 1,
87  ID_About,
88  ID_MANUAL_EXPOSURE,
89  ID_SLIDER_FREQUENCY,
90  ID_SLIDER_INTEGRATIONTIME,
91  //ID_SLIDER_EXPOSURE,
93  ID_BUTTON_WB,
94  ID_CANVAS,
95  ID_TIMER = 1001
96 };
97 
98 
99 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
100  EVT_MENU(ID_Quit, MyFrame::OnQuit)
101  EVT_MENU(ID_About, MyFrame::OnAbout)
102  EVT_COMMAND_SCROLL(ID_SLIDER_FREQUENCY, MyFrame::OnFrequency)
103  EVT_COMMAND_SCROLL(ID_SLIDER_INTEGRATIONTIME, MyFrame::OnIntegrationTime)
104  EVT_BUTTON(ID_BUTTON_QUIT, MyFrame::OnQuit)
105  EVT_TIMER(ID_TIMER, MyFrame::OnTimer)
106 END_EVENT_TABLE()
107 
108 IMPLEMENT_APP(MyApp)
109 
110 
111 bool MyApp::OnInit()
112 {
113  MyFrame *frame =
114  new MyFrame( wxT("PMDCamToShm"), wxPoint(0,700), wxSize(250,300) );
115  frame->Show(TRUE);
116  SetTopWindow(frame);
117  return TRUE;
118 }
119 
120 
121 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
122  : wxFrame((wxFrame *)NULL, -1, title, pos, size)
123 {
124  wxMenu *menuFile = new wxMenu;
125 
126  menuFile->Append( ID_About, wxT("&About...") );
127  menuFile->AppendSeparator();
128  menuFile->Append( ID_Quit, wxT("E&xit") );
129 
130  wxMenuBar *menuBar = new wxMenuBar;
131  menuBar->Append( menuFile, wxT("&File") );
132 
133  SetMenuBar( menuBar );
134 
135  wxSizer *Sizer = new wxBoxSizer( wxVERTICAL );
136 
137  wxStaticText *FrequencyLabel =
138  new wxStaticText(this, -1, AsciiToWx("Modulation Frequency[MHz] "));
139  SliderFrequency_ =
140  new wxSlider(this, ID_SLIDER_FREQUENCY, 20, 0, 60, wxDefaultPosition,
141  wxDefaultSize,wxSL_LABELS | wxSL_HORIZONTAL, wxDefaultValidator,
142  AsciiToWx("slider_frequency"));
143 
144  wxStaticText *TimeLabel =
145  new wxStaticText(this, -1, AsciiToWx("Integration Time [us]"));
146  SliderIntegrationTime_ =
147  new wxSlider(this, ID_SLIDER_INTEGRATIONTIME, 20000, 0, 80000, wxDefaultPosition,
148  wxDefaultSize, wxSL_LABELS | wxSL_HORIZONTAL, wxDefaultValidator,
149  AsciiToWx("slider_integrationtime"));
150 
151  QuitButton_ =
152  new wxButton(this, ID_BUTTON_QUIT, AsciiToWx("Quit"), wxDefaultPosition,
153  wxDefaultSize, 0, wxDefaultValidator,
154  AsciiToWx("button"));
155 
156 
157 
158  Sizer->Add(FrequencyLabel, 0, wxCENTER|wxTOP|wxRIGHT|wxLEFT, 10);
159  Sizer->Add(SliderFrequency_, 0, wxCENTER|wxALL|wxEXPAND, 10);
160  Sizer->Add(TimeLabel, 0, wxCENTER|wxTOP|wxRIGHT|wxLEFT, 10);
161  Sizer->Add(SliderIntegrationTime_, 0, wxCENTER|wxALL|wxEXPAND,10);
162  Sizer->Add(QuitButton_, 0, wxCENTER|wxALL,10);
163  SetSizer( Sizer );
164 
165  CreateStatusBar();
166  SetStatusText( wxT("") );
167 
168  Timer_.SetOwner(this, ID_TIMER);
169  ShmName_ = "PMD_SHM_MIP.shm";
170  cout <<"Using: "<<ShmName_<<endl;
171 
172  //here create the shm feeder
173  pShmFeeder_ = new VideoShMFeederPMD(ShmName_);
174 
175  Cam_.OpenDevice();
176  Cam_.PreGrab();
177  Cam_.InitImage(GrabImage_);
178 
179  framecount_ = 0;
180 
181  wxCommandEvent cevt;
182  wxScrollEvent evt;
183  OnGetFrequency(cevt);
184  OnGetIntegrationTime(cevt);
185  Timer_.Start(20, true);
186 }
187 
188 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
189 {
190  Cam_.PostGrab();
191  delete pShmFeeder_;
192  Close(TRUE);
193 }
194 
195 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
196 {
197  wxMessageBox(wxT("This Application grabs images from a PMD cam\n and stores them in a shared memory\n named: PMD_SHM_MIP"),
198  wxT("PMDCamToShm"), wxOK | wxICON_INFORMATION, this);
199 }
200 
201 void MyFrame::OnFrequency(wxScrollEvent& event)
202 {
203  int value = SliderFrequency_->GetValue();
204  int frequency = value;
205  if (Cam_.SetModulationFrequency(frequency)!=0){
206  BEXCEPTION("error setting camera");
207  }
208  cout << "setting frequency: "<<frequency<<endl;
209 }
210 
211 void MyFrame::OnIntegrationTime(wxScrollEvent& event)
212 {
213  int value = SliderIntegrationTime_->GetValue();
214  int time = value;
215  if (Cam_.SetIntegrationTime(time)!=0){
216  BEXCEPTION("error setting camera");
217  }
218  cout << "setting integration time: "<<time<<endl;
219 }
220 
221 void MyFrame::OnGetFrequency(wxCommandEvent& event)
222 {
223  unsigned int frequency = 0;
224  if(Cam_.GetModulationFrequency(frequency)<=0) {
225  BEXCEPTION("error getting camera");
226  }
227  SliderFrequency_->SetValue(frequency);
228  cout << "frequency: "<<frequency<<endl;
229 }
230 
231 void MyFrame::OnGetIntegrationTime(wxCommandEvent& event)
232 {
233 
234  unsigned int time = 0;
235  if (Cam_.GetIntegrationTime(time)<=0){
236  BEXCEPTION("error getting integration time");
237  }
238  SliderIntegrationTime_->SetValue(time);
239  cout << "integration time: "<<time<<endl;
240 }
241 
242 void MyFrame::OnTimer(wxTimerEvent& event)
243 {
244  Cam_.GrabSingle(GrabImage_);
245  Cam_.GrabSingleDepth(DepthImage_);
246  Cam_.GrabSingleModCoeff(ModCoeffImage_);
247 
248  pShmFeeder_->ProcessImage(&GrabImage_,&DepthImage_,&ModCoeffImage_);
249  cout <<framecount_++<<endl;
250  Timer_.Start(20, true); // grab new images every 20 ms = resp 50 Hz
251 }
252 /** \endcond */
253 
254 
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
extends the Image by MetaData support (e.g.
Definition: Camera.hh:74
class to save Images to a Sharerd memory.
Support for CamCube usb cam.