26 #include <Base/Common/BIASpragmaStart.hh>
28 #include <bias_config.h>
29 #include <Gui/ImageCanvasCheckerboardExtract.hh>
30 #include <Base/Image/Image.hh>
31 #include <Base/Image/ImageIO.hh>
32 #include <Base/Image/ImageConvert.hh>
33 #include <Image/ConvertHDR.hh>
37 #include <wx/spinctrl.h>
38 #include <Utils/Param.hh>
39 #include <Filter/Rescale.hh>
44 #include "Base/Common/getopt_W32.h"
50 #define PARAM_FILE_NAME "clickcorners.param"
52 #define HDR_STORAGETYPE float
74 class ClickImageCornersApp:
public wxApp
76 virtual bool OnInit();
83 class ClickCornersFrame :
88 ClickCornersFrame(
const wxString& title,
const wxPoint& pos,
const wxSize& size);
89 virtual ~ClickCornersFrame();
92 int Init(
int argc,
char* argv[]);
94 void CheckerboardSelected(std::vector<BIAS::HomgPoint2D> & corners,
95 bool bOnlyFourPointsGiven,
bool valid=
true);
97 void OnRescaleImage(wxSpinEvent& event);
99 void OnNext(wxCommandEvent& event);
100 void OnPrev(wxCommandEvent& event);
101 void OnSave(wxCommandEvent& event);
102 void OnInvalid(wxCommandEvent& event);
103 void OnHelp(wxCommandEvent& event);
104 void ShowText(
const string text,
int slot);
108 string MatlabFilename_;
109 double fRescaleImageFactor_;
113 std::vector<std::string> fileNames_;
114 vector<vector<BIAS::HomgPoint2D> > allCoords_;
115 vector<bool> bImageDone_;
117 unsigned int imageNumber_;
118 wxFlexGridSizer *Sizer_;
120 DECLARE_EVENT_TABLE()
129 DECLARE_APP(ClickImageCornersApp)
132 IMPLEMENT_APP(ClickImageCornersApp)
134 bool ClickImageCornersApp::OnInit()
136 ClickCornersFrame *frame_;
137 frame_ =
new ClickCornersFrame(wxT(
"ClickCorners"), wxPoint(50,50),
148 frame_->HandleImage();
149 SetTopWindow(frame_);
156 ClickCornersFrame(
const wxString& title,
const wxPoint& pos,
const wxSize& size):
157 wxFrame((wxFrame *)NULL, -1, title, pos, size)
160 Sizer_ =
new wxFlexGridSizer(1,2,0,0);
161 Sizer_->AddGrowableCol(0);
162 Sizer_->AddGrowableRow(0);
165 ic_->KeepScrollPosition(
true);
166 fRescaleImageFactor_ = 1.0;
168 wxSize buttonSize(65,30);
170 wxToolBar* toolBar = CreateToolBar();
171 wxButton *pBNext=
new wxButton(toolBar,
ID_Next, wxT(
"Next"),wxDefaultPosition,buttonSize);
172 wxButton *pBPrev=
new wxButton(toolBar,
ID_Prev, wxT(
"Previous"),wxDefaultPosition,buttonSize);
173 wxButton *pBSave=
new wxButton(toolBar,
ID_Save, wxT(
"Save"),wxDefaultPosition,buttonSize);
174 wxButton *pBInvalid=
new wxButton(toolBar,
ID_Invalid, wxT(
"Invalid"),wxDefaultPosition,buttonSize);
175 wxButton *pBHelp=
new wxButton(toolBar,
ID_Help, wxT(
"Help"),wxDefaultPosition,buttonSize);
176 wxSpinCtrl *pRescaleImageSpinCtrl_ =
new wxSpinCtrl(toolBar,
ID_RescaleImage,
177 wxT(
"Rescale"), wxDefaultPosition,wxSize(60,30),
178 wxSP_ARROW_KEYS,1,60,10,wxT(
"10"));
179 pRescaleImageSpinCtrl_->SetToolTip(wxT(
"Rescale image for corners selection."));
181 toolBar->AddControl(pBPrev);
182 toolBar->AddControl(pBNext);
183 toolBar->AddControl(pBSave);
184 toolBar->AddControl(pBInvalid);
185 toolBar->AddControl(pBHelp);
186 toolBar->AddControl(pRescaleImageSpinCtrl_);
189 Sizer_->Add(ic_,0,wxALL|wxEXPAND, 5);
192 SetMinSize(wxSize(700,550));
198 ~ClickCornersFrame(){
206 void ClickCornersFrame::
207 OnNext(wxCommandEvent& event){
208 if(imageNumber_ < fileNames_.size()-1 && bImageDone_[imageNumber_]){
212 else if(imageNumber_ == fileNames_.size()-1){
213 string message =
"Done! Now save the corners.";
215 wxT(
"Detector"), wxOK ,
this);
219 ShowText(
"Select Corners!",0);
222 void ClickCornersFrame::
223 OnPrev(wxCommandEvent& event){
224 if(imageNumber_ >=1 && bImageDone_[imageNumber_]){
229 ShowText(
"Select Corners!",0);
232 void ClickCornersFrame::
233 OnInvalid(wxCommandEvent& event){
234 std::vector<BIAS::HomgPoint2D> corners;
236 corners.push_back(c);
237 CheckerboardSelected(corners,
false,
true);
240 void ClickCornersFrame::
241 OnSave(wxCommandEvent& event){
245 void ClickCornersFrame::
246 OnHelp(wxCommandEvent& event){
248 message =
"This is the MIP corners clicking tool \nAfter selecting all corners in one image press \"Next\".\n\nFinally save the corners, pressing \"Save\".";
251 wxT(
"Detector"), wxOK ,
this);
254 void ClickCornersFrame::
255 OnRescaleImage(wxSpinEvent& event)
257 fRescaleImageFactor_ =
event.GetPosition()/10.0;
261 void ClickCornersFrame::
264 cout <<
"Usage: biasClickImageCornersWx -f Filename.m -x xnum -y ynum -d image1 image2 ..."<<endl
266 cout <<
" The tool tries to find checkerboards in the input images" << endl
267 <<
" finds corners also in fisheye distorted images and " << endl
268 <<
" writes these to the Matlab file 'Filename.m'." << endl
269 <<
" xnum and ynum are the number of the checkerboards inner corners."
271 <<
" -d writes debug images." << endl
272 <<
" Do not use .mip images since Matlab is unable to read them." << endl
277 int ClickCornersFrame::
278 Init(
int argc,
char* argv[])
280 MatlabFilename_ =
"ExtractedCorners.m";
282 bWriteDebug_ =
false;
285 int *colorDepth = AddParamInt(
"colorDepth",
"color depth in bit", 8);
286 int *corners = AddParamInt(
"corners",
"Number of Points", 1,1,1000,
'c');
287 string *imageList = AddParamString(
"ImageList",
"List with images",
"");
290 UpdateParameter(argc, argv, PARAM_FILE_NAME);
294 Param::ParseListFile(*imageList,fileNames_);
295 allCoords_.resize(fileNames_.size());
296 bImageDone_.resize(fileNames_.size());
297 for(
unsigned i=0;i<fileNames_.size();i++)
298 bImageDone_[i] =
false;
300 colorDepth_ = *colorDepth;
302 ic_->SetPatternParameters( corners_, 1);
303 ic_->ManuallySetSelectionMode(
true);
308 void ClickCornersFrame::
315 if(colorDepth_ != 8){
317 ImageConvert::ConvertST(image, imageFl, ImageBase::ST_float);
321 ImageConvert::ConvertST(image, imageUC, ImageBase::ST_unsignedchar);
332 if(fRescaleImageFactor_ != 1.0){
333 if(fRescaleImageFactor_ >1.0){
334 rescaler_.Upsample (imageUC, imageUC2,
335 imageUC.
GetWidth() * fRescaleImageFactor_,
336 imageUC.
GetHeight() * fRescaleImageFactor_);
338 else if(fRescaleImageFactor_ <1.0){
339 rescaler_.Downsample (imageUC, imageUC2,
340 imageUC.
GetWidth() * fRescaleImageFactor_,
341 imageUC.
GetHeight() * fRescaleImageFactor_);
343 ic_->Show(imageUC2,
"Select");
346 ic_->Show(imageUC,
"Select");
348 ic_->SetPatternParameters (corners_,1);
349 ic_->ManuallySetSelectionMode(
true);
350 if( bImageDone_[imageNumber_])
351 ic_->DisplayCheckerboardCorners(allCoords_[imageNumber_],fRescaleImageFactor_);
353 ic_->SelectCheckerboardCorners(*
this,
true,
false);
357 void ClickCornersFrame::
358 CheckerboardSelected(std::vector<BIAS::HomgPoint2D> & corners,
bool bOnlyFourPointsGiven,
bool valid){
359 if(bOnlyFourPointsGiven){
360 ShowText(
"Only four points, this is invalid!",0);
365 allCoords_[imageNumber_].clear();
366 for(
unsigned int k=0;k< corners.size();k++){
367 corners[k][0] /= fRescaleImageFactor_;
368 corners[k][1] /= fRescaleImageFactor_;
369 allCoords_[imageNumber_].push_back(corners[k]);
371 ShowText(
"Points selected!",0);
372 bImageDone_[imageNumber_] =
true;
376 void ClickCornersFrame::
380 wxFileDialog dialog(
this,wxT(
"Save Corners"),wxT(
""),wxT(
""),
381 wxT(
"Matlab (*.m)|*.m"),
382 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
383 int ret = dialog.ShowModal();
385 fileName = dialog.GetPath();
386 ofstream ofs(WxToAscii(fileName));
396 for (
unsigned int i=0; i<allCoords_.size(); i++) {
397 for (
unsigned int j=0; j<allCoords_[i].size(); j++) {
398 ofs << (allCoords_[i][j])[0] <<
" "<<(allCoords_[i][j])[1]<< endl;
405 void ClickCornersFrame::
406 ShowText(
const string text,
int slot){
407 if(GetStatusBar() != NULL)
408 GetStatusBar()->SetStatusText(
AsciiToWx(text),slot);
411 BEGIN_EVENT_TABLE(BIAS::ClickCornersFrame, wxFrame)
412 EVT_BUTTON (ID_Next, ClickCornersFrame::OnNext)
413 EVT_BUTTON (ID_Prev, ClickCornersFrame::OnPrev)
414 EVT_BUTTON (ID_Save, ClickCornersFrame::OnSave)
415 EVT_BUTTON (ID_Invalid, ClickCornersFrame::OnInvalid)
416 EVT_BUTTON (ID_Help, ClickCornersFrame::OnHelp)
417 EVT_SPINCTRL (ID_RescaleImage,ClickCornersFrame::OnRescaleImage)
421 #include <Base/Common/BIASpragmaEnd.hh>
This class handles conversions of HDR images to for example unsigned char.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
int ToUnsignedCharGamma(BIAS::Image< StorageType > &src, BIAS::Image< unsigned char > &dst, float gamma, unsigned int currentMaxVal)
Conversion to unsigned char image, leaves min/max part intact.
unsigned int GetWidth() const
unsigned int GetHeight() const
enum EColorModel GetColorModel() const
This class Param provides generic support for parameters.
callback interface for ImageCanvasCheckerBoardExtract
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Class for converting an array of wxStrings to an array of non-const ASCII strings.
enum EStorageType GetStorageType() const
This is the base class for images in BIAS.
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.
static int ToGrey(const ImageBase &source, ImageBase &dest)
wrapper for the templated function ToGrey