35 #include <VideoSource/VideoSource_MDcam.hh>
36 #include <Utils/Param.hh>
38 #include <VideoSource/VideoShMFeeder.hh>
40 #include <Gui/StringConv.hh>
41 #include <Base/Debug/Exception.hh>
47 class MyApp :
public wxApp
49 virtual bool OnInit();
52 class MyFrame:
public wxFrame
56 MyFrame(
const wxString& title,
const wxPoint& pos,
const wxSize& size);
58 void OnQuit(wxCommandEvent& event);
59 void OnWhiteBalance(wxCommandEvent& event);
60 void OnAbout(wxCommandEvent& event);
61 void OnAutoExposure(wxCommandEvent& event);
62 void OnGain(wxScrollEvent& event);
63 void OnShutter(wxScrollEvent& event);
64 void OnTimer(wxTimerEvent& event);
68 wxButton *QuitButton_, *WhiteBalanceButton_;
69 wxCheckBox *AutoExposure_;
70 wxSlider *SliderGain_;
71 wxSlider *SliderShutter_;
76 Camera<
unsigned char> *GrabImage;
77 vector<
string> ShmNames;
79 const
string ShmPrefix;
84 const
float max_shutter;
102 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
103 EVT_MENU(
ID_Quit, MyFrame::OnQuit)
104 EVT_MENU(
ID_About, MyFrame::OnAbout)
105 EVT_CHECKBOX(ID_MANUAL_EXPOSURE, MyFrame::OnAutoExposure)
106 EVT_COMMAND_SCROLL(ID_SLIDER_GAIN, MyFrame::OnGain)
107 EVT_COMMAND_SCROLL(ID_SLIDER_SHUTTER, MyFrame::OnShutter)
108 EVT_BUTTON(ID_BUTTON_WB, MyFrame::OnWhiteBalance)
110 EVT_TIMER(
ID_TIMER, MyFrame::OnTimer)
119 new MyFrame( wxT(
"MDCam2ShmWx"), wxPoint(50,50), wxSize(450,340) );
126 MyFrame::MyFrame(
const wxString& title,
const wxPoint& pos,
const wxSize& size)
127 : wxFrame((wxFrame *)NULL, -1, title, pos, size), camfile(
"cameras.conf"),
128 ShmPrefix(
"MDCamShm"), max_gain(30.0), max_shutter(0.03)
130 wxMenu *menuFile =
new wxMenu;
132 menuFile->Append( ID_About, wxT(
"&About...") );
133 menuFile->AppendSeparator();
134 menuFile->Append( ID_Quit, wxT(
"E&xit") );
136 wxMenuBar *menuBar =
new wxMenuBar;
137 menuBar->Append( menuFile, wxT(
"&File") );
139 SetMenuBar( menuBar );
141 wxSizer *Sizer =
new wxBoxSizer( wxVERTICAL );
144 new wxCheckBox(
this, ID_MANUAL_EXPOSURE,
AsciiToWx(
"Auto Exposure"),
145 wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
148 wxStaticText *GainLabel =
149 new wxStaticText(
this, -1,
AsciiToWx(
"Gain"));
151 new wxSlider(
this, ID_SLIDER_GAIN, 50, 0, 255, wxDefaultPosition,
152 wxDefaultSize, wxSL_HORIZONTAL, wxDefaultValidator,
155 wxStaticText *ShutterLabel =
156 new wxStaticText(
this, -1,
AsciiToWx(
"Shutter"));
158 new wxSlider(
this, ID_SLIDER_SHUTTER, 255, 0, 255, wxDefaultPosition,
159 wxDefaultSize, wxSL_HORIZONTAL, wxDefaultValidator,
163 new wxButton(
this, ID_BUTTON_QUIT,
AsciiToWx(
"Quit"), wxDefaultPosition,
164 wxDefaultSize, 0, wxDefaultValidator,
167 WhiteBalanceButton_ =
168 new wxButton(
this, ID_BUTTON_WB,
AsciiToWx(
"White Balance"),
169 wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
172 Sizer->Add(AutoExposure_, 0, wxCENTER|wxALL|wxEXPAND,10);
173 Sizer->Add(GainLabel, 0, wxCENTER|wxTOP|wxRIGHT|wxLEFT, 10);
174 Sizer->Add(SliderGain_, 0, wxCENTER|wxALL|wxEXPAND, 10);
175 Sizer->Add(ShutterLabel, 0, wxCENTER|wxTOP|wxRIGHT|wxLEFT, 10);
176 Sizer->Add(SliderShutter_, 0, wxCENTER|wxALL|wxEXPAND,10);
177 Sizer->Add(WhiteBalanceButton_, 0, wxCENTER|wxALL,10);
178 Sizer->Add(QuitButton_, 0, wxCENTER|wxALL,10);
183 SetStatusText( wxT(
"") );
185 Timer_.SetOwner(
this, ID_TIMER);
191 numcams = cams.InitCameras(camfile);
192 if (numcams <0) exit(0);
195 for (
int i=0; i<numcams; i++) {
196 cams.GetCamera(i)->InitImage(GrabImage[i]);
198 oss<<ShmPrefix<<
"-"<<cams.GetCamera(i)->GetID();
199 ShmNames.push_back(oss.str());
201 cout <<
"Using: "<<ShmNames[i]<<endl;
204 ShmFeeder.push_back(s);
210 AutoExposure_->SetValue(
false);
212 OnAutoExposure(cevt);
216 Timer_.Start(20,
true);
219 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
222 cams.ReleaseCameras();
223 for (
unsigned int i=0;i<ShmFeeder.size(); i++)
228 void MyFrame::OnWhiteBalance(wxCommandEvent& WXUNUSED(event))
230 cams.OnePushAuto(DC1394_FEATURE_WHITE_BALANCE);
231 cerr <<
"\nwhite balance"<<endl;
234 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
236 wxMessageBox(wxT(
"This is a wxWidgets Hello world sample"),
237 wxT(
"About Hello World"), wxOK | wxICON_INFORMATION,
this);
240 void MyFrame::OnAutoExposure(wxCommandEvent& event)
242 bool auto_exposure = AutoExposure_->IsChecked();
245 int value = SliderGain_->GetValue();
246 float gain = (float)value / 255.0 * max_gain;
247 value = SliderShutter_->GetValue();
248 float shutter = (float)value / 255.0 * max_shutter;
249 if (cams.AutoMode(DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_AUTO)!=0){
250 BEXCEPTION(
"error setting camera");
252 if (cams.AutoMode(DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_AUTO)!=0){
253 BEXCEPTION(
"error setting camera");
255 if (cams.SetGain(gain)!=0){
256 BEXCEPTION(
"error setting camera");
258 if (cams.SetShutter(shutter)!=0){
259 BEXCEPTION(
"error setting camera");
262 if (cams.AutoMode(DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL)!=0){
263 BEXCEPTION(
"error setting camera");
265 if (cams.AutoMode(DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL)!=0){
266 BEXCEPTION(
"error setting camera");
271 void MyFrame::OnGain(wxScrollEvent& event)
273 if (!AutoExposure_->IsChecked()){
274 int value = SliderGain_->GetValue();
275 float gain = (float)value / 255.0 * max_gain;
276 if (cams.SetGain(gain)!=0){
277 BEXCEPTION(
"error setting camera");
283 void MyFrame::OnShutter(wxScrollEvent& event)
285 if (!AutoExposure_->IsChecked()){
286 int value = SliderShutter_->GetValue();
287 float shutter = (float)value / 255.0 * max_shutter;
288 if (cams.SetShutter(shutter)!=0){
289 BEXCEPTION(
"error setting camera");
295 void MyFrame::OnTimer(wxTimerEvent& event)
297 cams.GrabSingle(GrabImage);
299 for (
int i=0; i<numcams; i++) {
300 ShmFeeder[i]->ProcessImage(&(GrabImage[i]));
303 cout <<framecount++<<endl;
304 Timer_.Start(20,
true);
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
extends the Image by MetaData support (e.g.
VideoSource_MDcam simplifies acces to more then one DCam. It suports multiple IEEE1394-adapters, extern synchronization via parallel port and networked capture cluster.
class to save Images to a Sharerd memory