27 # pragma warning(disable: 4251) // STL MAP DLL
28 # pragma warning(disable: 4005) // VS8 wx
29 # pragma warning(disable: 4996) // wx localtime
34 #include <Gui/ConsoleRedirectIO.hh>
35 #include <Gui/ImageCanvas.hh>
36 #include <Gui/PlainImageCanvas.hh>
37 #include <Gui/StringConv.hh>
38 #include <Base/Common/W32Compat.hh>
39 #include <Base/Image/ImageIO.hh>
40 #include <Base/ImageUtils/ImageDraw.hh>
41 #include <Base/Image/ImageConvert.hh>
42 #include <Base/ImageUtils/Bresenham.hh>
43 #include <Image/Camera.hh>
44 #include <Geometry/PMatrix.hh>
45 #include <Geometry/FMatrix.hh>
46 #include <Geometry/EpipolarLine.hh>
47 #include <Geometry/ProjectionParametersSpherical.hh>
50 #include <wx/splitter.h>
71 const int HALF_CUTOUT_SIZE = 30;
72 const int CUTOUT_SIZE = 2 * HALF_CUTOUT_SIZE;
82 int srcX,
int srcY,
int srcWidth,
int srcHeight,
int scale)
84 int dstWidth = srcWidth * scale;
85 int dstHeight = srcHeight * scale;
91 dst.
Init(dstWidth, dstHeight, 3);
96 for (
int x = srcX; x < srcX + srcWidth; x++)
98 for (
int y = srcY; y < srcY + srcHeight; y++)
100 unsigned char pixel[3];
111 pixel[0] = srcIda[y][x];
112 pixel[1] = srcIda[y][x];
113 pixel[2] = srcIda[y][x];
118 pixel[0] = srcIda[y][3*x+0];
119 pixel[1] = srcIda[y][3*x+1];
120 pixel[2] = srcIda[y][3*x+2];
124 int startX = (x - srcX) * scale;
125 int startY = (y - srcY) * scale;
127 for (
int i = startX; i < startX + scale; i++)
129 for (
int j = startY; j < startY + scale; j++)
133 dstIda[j][3*i+0] = pixel[0];
134 dstIda[j][3*i+1] = pixel[1];
135 dstIda[j][3*i+2] = pixel[2];
146 class CutoutFrame :
public wxFrame
149 CutoutFrame(
wxWindow* parent,
const wxString& title);
152 void SetTransform(
int offsetX,
int offsetY,
int scale);
155 int _OffsetX, _OffsetY, _Scale;
158 void OnMotion(wxMouseEvent& event);
159 void OnLeaveWindow(wxMouseEvent& event);
160 void OnClose(wxCloseEvent& event);
161 void OnKeyDown(wxKeyEvent& keyEvent);
162 void OnCharEvt(wxKeyEvent& keyEvent);
165 DECLARE_EVENT_TABLE()
169 BEGIN_EVENT_TABLE(CutoutFrame, wxFrame)
170 EVT_MOTION(CutoutFrame::OnMotion)
171 EVT_LEAVE_WINDOW(CutoutFrame::OnLeaveWindow)
172 EVT_CLOSE(CutoutFrame::OnClose)
173 EVT_KEY_DOWN(CutoutFrame::OnKeyDown)
174 EVT_CHAR(CutoutFrame::OnCharEvt)
177 void CutoutFrame::OnKeyDown(wxKeyEvent& event)
179 if (GetParent() != NULL)
181 GetParent()->GetEventHandler()->ProcessEvent(event);
186 void CutoutFrame::OnCharEvt(wxKeyEvent& event)
188 if (GetParent() != NULL)
190 GetParent()->GetEventHandler()->ProcessEvent(event);
195 CutoutFrame::CutoutFrame(
wxWindow* parent,
const wxString& title)
196 : wxFrame(parent, -1, title,
197 wxDefaultPosition, wxDefaultSize,
198 wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT)
208 wxBoxSizer* sizer =
new wxBoxSizer(wxHORIZONTAL);
209 sizer->Add(_ImageCanvas);
215 _ImageCanvas->Show(image, name);
216 _ImageCanvas->SetScrollbars(0, 0, 0, 0);
221 void CutoutFrame::SetTransform(
int offsetX,
int offsetY,
int scale)
228 void CutoutFrame::OnMotion(wxMouseEvent& event)
232 wxPoint pos =
event.GetPosition();
233 int x = dc.DeviceToLogicalX(pos.x) / _Scale + _OffsetX;
234 int y = dc.DeviceToLogicalY(pos.y) / _Scale + _OffsetY;
236 text <<
"(x, y) = (" << x <<
", " << y <<
")";
237 GetStatusBar()->SetStatusText(
AsciiToWx(text.str()));
240 void CutoutFrame::OnLeaveWindow(wxMouseEvent&)
242 GetStatusBar()->SetStatusText(wxT(
""));
245 void CutoutFrame::OnClose(wxCloseEvent& event)
265 ID_THICKER_LINE= wxID_HIGHEST+100,
270 class MainFrame :
public wxFrame
278 const string& name2,
bool homographymode =
false);
281 const double& maximagewidth);
284 bool onlyHomography_;
293 std::string _ImageName1, _ImageName2;
294 CutoutFrame* _CutoutFrame1;
295 CutoutFrame* _CutoutFrame2;
296 wxPoint _SelectedPoint1;
297 wxPoint _SelectedPoint2;
299 void OnLeftDown(wxMouseEvent& event);
300 void OnKeyDown(wxKeyEvent& keyEvent);
301 void OnCharEvt(wxKeyEvent& keyEvent);
302 void ThickerLine(wxCommandEvent& event);
303 void ThinnerLine(wxCommandEvent& event);
304 void SaveImages(wxCommandEvent& event);
316 DECLARE_EVENT_TABLE()
319 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
320 EVT_LEFT_DOWN(MainFrame::OnLeftDown)
321 EVT_MENU(ID_THICKER_LINE, MainFrame::ThickerLine)
322 EVT_MENU(ID_THINNER_LINE, MainFrame::ThinnerLine)
323 EVT_MENU(ID_SAVE_IMAGES, MainFrame::SaveImages)
326 void MainFrame::SaveImages(wxCommandEvent& event){
331 void MainFrame::ThickerLine(wxCommandEvent& event)
334 cout<<
" "<<epiLineWidth_<<endl;
336 _ImageCanvas1->GetViewStart(&x1, &y1);
337 _ImageCanvas1->GetViewStart(&x2, &y2);
338 _ImageCanvas1->Show(_Image1, _ImageName1);
339 _ImageCanvas2->Show(_Image2, _ImageName2);
340 _ImageCanvas1->Scroll(x1, y1);
341 _ImageCanvas1->Scroll(x2, y2);
345 void MainFrame::ThinnerLine(wxCommandEvent& event)
348 if(epiLineWidth_<1) epiLineWidth_=1;
349 cout<<
" "<<epiLineWidth_<<endl;
351 _ImageCanvas1->GetViewStart(&x1, &y1);
352 _ImageCanvas1->GetViewStart(&x2, &y2);
353 _ImageCanvas1->Show(_Image1, _ImageName1);
354 _ImageCanvas2->Show(_Image2, _ImageName2);
355 _ImageCanvas1->Scroll(x1, y1);
356 _ImageCanvas1->Scroll(x2, y2);
363 MainFrame::MainFrame()
364 : wxFrame(NULL, -1, wxT(
"BiasShowEpiWX")),
365 pointatinfinity_ (0.0, 0.0, 0.0, 0.0), epiLineWidth_(1)
367 _CutoutFrame1 =
new CutoutFrame(
this, wxT(
"Cutout 1"));
368 _CutoutFrame2 =
new CutoutFrame(
this, wxT(
"Cutout 2"));
369 onlyHomography_ =
false;
375 menuBar_ =
new wxMenuBar;
377 file_->Append(ID_SAVE_IMAGES, wxT(
"&Save"));
379 drawing_ =
new wxMenu;
380 drawing_->Append(ID_THICKER_LINE, wxT(
"&Increase Line Width"));
381 drawing_->Append(ID_THINNER_LINE, wxT(
"&Decrease Line Width"));
384 menuBar_->Append(file_, wxT(
"&File"));
385 menuBar_->Append(drawing_, wxT(
"&Display"));
386 SetMenuBar(menuBar_);
401 const unsigned char Value[3]={255,0,0};
402 bool epipoleIsInImage =
406 if (epipoleIsInImage) {
408 int(rint(orig_epipole[0])),
409 int(rint(orig_epipole[1])),
412 int(rint(orig_epipole[0])),
413 int(rint(orig_epipole[1])),
425 const unsigned char Blue[3]={0,0,255};
426 const unsigned char Green[3]={0,255,0};
427 int radius = (int(rint(pPPS->
GetRadius())));
438 for (
unsigned int i = 0; i<4; i++) {
441 if (point.
NormL2()<1e-10)
break;
444 int(rint((point-pp).NormL2())),
456 PaintedImage1_ = _Image1 = image1;
457 PaintedImage2_ = _Image2 = image2;
458 _Projection1 = proj1;
459 _Projection2 = proj2;
465 if (ppp1!=NULL && ppp2!=NULL) {
469 cout<<
"F is "<<F<<endl;
481 if (((_Projection1.GetC()-_Projection2.GetC()).NormL2()<1e-8)
483 BIASWARN(endl<<endl<<endl<<
484 "Homography mode or very small baseline, using only H_infinity!"
486 onlyHomography_ =
true;
489 DrawEpipole(_Image1, _Projection1, _Projection2);
490 DrawEpipole(_Image2, _Projection2, _Projection1);
492 ShowSphericalParameters(_Image1, _Projection1);
493 ShowSphericalParameters(_Image2, _Projection2);
495 _ImageCanvas1->Show(_Image1, _ImageName1);
496 _ImageCanvas2->Show(_Image2, _ImageName2);
497 _ImageCanvas1->SetClearDrawingContext(
false);
498 _ImageCanvas2->SetClearDrawingContext(
false);
500 wxBoxSizer* sizer =
new wxBoxSizer(wxHORIZONTAL);
501 sizer->Add(_ImageCanvas1, 1, wxEXPAND);
503 sizer->Add(_ImageCanvas2, 1, wxEXPAND);
505 sizer->SetItemMinSize(_ImageCanvas1, 100, 100);
506 sizer->SetItemMinSize(_ImageCanvas2, 100, 100);
509 sizer->SetSizeHints(
this);
519 const double& maximagewidth) {
521 double imageSize = maximagewidth + 1.0;
523 double maxangle = M_PI/2.0-0.01;
526 while (imageSize>maximagewidth) {
529 BIASASSERT(maxangle>0.0);
531 fakeParamsPersp1->
SetC(paramsSpherical1->
GetC());
532 fakeParamsPersp1->
SetQ(paramsSpherical1->
GetQ());
533 fakeParamsPersp1->
SetK(K);
534 fakeParamsPersp1->
SetImageSize((
int)imageSize, (
int)imageSize);
539 void MainFrame::OnLeftDown(wxMouseEvent& event)
544 (_Projection1.GetParameters());
545 int image1Width = _Image1.GetWidth();
546 int image1Height = _Image1.GetHeight();
550 if (paramsPersp1==NULL) {
553 image1Width = image1Height = (int)rint(
554 GenerateVirtualPerspectiveCamera(_Projection1.GetParameters(),
557 paramsPersp1 = &fakeParamsPersp1;
558 cout<<
"Simulating epipolar geometry with perspective image of size "
566 int image2Width = _Image2.GetWidth();
567 int image2Height = _Image2.GetHeight();
571 if (paramsPersp2==NULL) {
573 image2Width = image2Height =
574 (int)rint(GenerateVirtualPerspectiveCamera(_Projection2.GetParameters(),
576 image2Width * 100.0));
577 paramsPersp2 = &fakeParamsPersp2;
582 if (event.GetEventObject() == _ImageCanvas1) {
584 _ImageCanvas1->PrepareDC(dc);
586 _SelectedPoint1.x = dc.DeviceToLogicalX(event.GetX());
587 _SelectedPoint1.y = dc.DeviceToLogicalY(event.GetY());
590 HomgPoint2D point(_SelectedPoint1.x, _SelectedPoint1.y, 1.0);
593 if (paramsPersp1== NULL) {
595 _Projection1.GetParameters()->UnProjectLocal(point, pos, ray);
597 BIASERR(
"clicked on point out of valid area !");
609 PaintedImage1_ = _Image1;
610 PaintedImage2_ = _Image2;
622 _Projection1.UnProjectToRay(
HomgPoint2D(_SelectedPoint1.x, _SelectedPoint1.y, 1.0), p, dir);
625 pointatinfinity_[3] = 0.0;
626 cout<<
"Point at infinity is "<<pointatinfinity_<<endl;
627 cout<<
"line width "<<epiLineWidth_<<endl;
629 if (_Projection2.DoesPointProjectIntoImage(pointatinfinity_,
631 pointimage2.Homogenize();
634 int(rint(pointimage2[0])),
635 int(rint(pointimage2[1])),
638 BIASERR(
"Point at infinity does not project into image 2:"<<pointimage2);
640 if (!onlyHomography_){
644 F12.GetEpipolesHomogenized(epipole1, epipole2);
648 if (eline1.
NormL2()>1e-10) {
650 HomgPoint2D clickedpoint(_SelectedPoint1.x, _SelectedPoint1.y);
652 _Projection1.UnProjectToRay(clickedpoint, pointOnRay, dirRay);
658 (
unsigned char*)NULL,
660 _Projection1.UnProjectToRay(clickedpoint, pointOnRay, dirRay);
665 (
unsigned char*)NULL,
670 BIASERR(
"You clicked ("<<_SelectedPoint1.x<<
";"<<_SelectedPoint1.y
671 <<
" which is undefined or pretty close to the epipole "
672 <<
" , in idealized perspective image "<<point<<
" and epipole="
674 <<
" resulting in eline "<<eline1);
679 _ImageCanvas1->GetViewStart(&x1, &y1);
680 _ImageCanvas1->GetViewStart(&x2, &y2);
681 _ImageCanvas1->Show(PaintedImage1_, _ImageName1);
682 _ImageCanvas2->Show(PaintedImage2_, _ImageName2);
683 _ImageCanvas1->Scroll(x1, y1);
684 _ImageCanvas1->Scroll(x2, y2);
688 ComputeCutoutImage(_Image1, CutoutImage,
689 _SelectedPoint1.x - HALF_CUTOUT_SIZE,
690 _SelectedPoint1.y - HALF_CUTOUT_SIZE,
691 CUTOUT_SIZE, CUTOUT_SIZE, SCALE);
694 2 + (_SelectedPoint1.x - (_SelectedPoint1.x - HALF_CUTOUT_SIZE)) * SCALE,
695 2 + (_SelectedPoint1.y - (_SelectedPoint1.y - HALF_CUTOUT_SIZE)) * SCALE, SCALE);
697 2 + (_SelectedPoint1.x - (_SelectedPoint1.x - HALF_CUTOUT_SIZE)) * SCALE,
698 2 + (_SelectedPoint1.y - (_SelectedPoint1.y - HALF_CUTOUT_SIZE)) * SCALE, SCALE * 4);
700 _CutoutFrame1->ShowImage(CutoutImage, _ImageName1);
701 _CutoutFrame1->SetTransform(_SelectedPoint1.x - HALF_CUTOUT_SIZE,
702 _SelectedPoint1.y - HALF_CUTOUT_SIZE, SCALE);
703 _CutoutFrame1->Show(TRUE);
704 _CutoutFrame1->Fit();
709 if (event.GetEventObject() == _ImageCanvas2)
712 _ImageCanvas2->PrepareDC(dc);
714 _SelectedPoint2.x = dc.DeviceToLogicalX(event.GetX());
715 _SelectedPoint2.y = dc.DeviceToLogicalY(event.GetY());
719 if ((event.GetEventObject() == _ImageCanvas1 && _CutoutFrame2->IsShown()) ||
720 event.GetEventObject() == _ImageCanvas2)
723 ComputeCutoutImage(_Image2, CutoutImage,
724 _SelectedPoint2.x - HALF_CUTOUT_SIZE,
725 _SelectedPoint2.y - HALF_CUTOUT_SIZE,
726 CUTOUT_SIZE, CUTOUT_SIZE, SCALE);
728 HomgPoint2D point(_SelectedPoint1.x, _SelectedPoint1.y, 1.0);
733 CutoutTransform[0][0] = CutoutTransform[1][1] = 1.0 / (double)SCALE;
734 CutoutTransform[0][2] = (double)(_SelectedPoint2.x - HALF_CUTOUT_SIZE);
735 CutoutTransform[1][2] = (double)(_SelectedPoint2.y - HALF_CUTOUT_SIZE);
738 if (_Projection2.DoesPointProjectIntoImage(pointatinfinity_,
739 endofepipolarline)) {
742 BIASASSERT(CutoutTransform.
GetInverse(CutoutTransformInv)==0);
744 CutoutTransform.
GetInverse(CutoutTransformInv);
746 endofepipolarline = CutoutTransformInv * endofepipolarline;
747 endofepipolarline.Homogenize();
751 int(rint(endofepipolarline[1]))
755 int(rint(endofepipolarline[1]))
761 int(rint(endofepipolarline[0])),
762 int(rint(endofepipolarline[1])),
766 BIASERR(
"Point at infinity does not project into image 2:"
767 <<endofepipolarline);
772 if (!onlyHomography_) {
774 FCutout = CutoutTransform.
Transpose() * FCutout;
775 FCutout.GetEpipolesHomogenized(epipole1, epipole2);
781 eline = FCutout * point;
782 eline.
Recalc(CUTOUT_SIZE*SCALE, CUTOUT_SIZE*SCALE, epipole2, epos2);
789 cx -= _SelectedPoint2.x - HALF_CUTOUT_SIZE;
790 cy -= _SelectedPoint2.y - HALF_CUTOUT_SIZE;
793 pB->
Rescale(1.0/
double(SCALE));
795 HomgPoint2D clickedpoint(_SelectedPoint1.x, _SelectedPoint1.y);
796 _Projection1.UnProjectToRay(clickedpoint, pointOnRay, dirRay);
801 (
unsigned char*)NULL,
811 _CutoutFrame2->ShowImage(CutoutImage, _ImageName2);
812 _CutoutFrame2->SetTransform(_SelectedPoint2.x - HALF_CUTOUT_SIZE,
813 _SelectedPoint2.y - HALF_CUTOUT_SIZE, SCALE);
814 _CutoutFrame2->Show(TRUE);
815 _CutoutFrame2->Fit();
821 cout<<endl<<
"biasshowepiwx is part of the BIAS library."<<endl;
822 cout<<
"See www.mip.informatik.uni-kiel.de for new versions."<<endl<<endl;
823 cout<<
"Usage: "<<endl;
824 cout<<
" biasshowepiwx img1 img2 [projection1 projection2]"<<endl;
826 cout<<
"This tool loads two images with known camera parameters (intrinsics"
827 <<
" and extrinsics) and shows them in a window."
828 <<
" Click a point in the left image and you will see the ray in space"
829 <<
" projected into the other image (epipolar line). If you have a"
830 <<
" fisheye image or an image with radial distortion, the line will"
831 <<
" be curved. The camera parameters can be in BIAS::Camera format"
832 <<
" within the image meta data (pgm, ppm, mip) or can be given as "
833 <<
" separate files on the command line. File formats supported are "
834 <<
" those of BIAS::Projection::Load(), namely"<<endl
835 <<
" - projection file in xml written by BIAS::Projection::XMLWrite"
837 <<
" - camera parameter file compatible with BIAS::CameraParam class"
839 <<
" - .cam file of BBC's FreeD tracking system"<<endl
840 <<
" - projection matrix in .mat file compatible with BIAS::PMatrix"
842 cout<<
"The small square shows the vanishing point of the epipolar line "
843 <<
" where the feature would lie with pure camera rotation, while the "
844 <<
"circle indicates the other end of the epipolar line (the epipole),"
845 <<
" which is the projection of the other camera center into the image."
846 <<
" Both ends and even the line as a whole may or may not be in the"
847 <<
" image, depending on your camera parameters."<<endl
848 <<
" Left clicking opens an enlarged window."<<endl;
860 ID_SELECT_LEFT_IMAGE = wxID_HIGHEST+188,
861 ID_SELECT_RIGHT_IMAGE,
863 ID_SELECT_RIGHT_PROJ,
873 class IntroductionFrame :
public wxDialog
876 IntroductionFrame(wxFrame* parent,
877 const wxString& title,
881 void OnButtonLeftImage( wxCommandEvent& event );
882 void OnButtonRightImage( wxCommandEvent& event );
883 void OnButtonLeftProj( wxCommandEvent& event );
884 void OnButtonRightProj( wxCommandEvent& event );
885 void OnButtonOK( wxCommandEvent& event );
886 void OnButtonCancel( wxCommandEvent& event );
887 void SetStrings(wxString* image1,wxString* image2,
888 wxString* proj1,wxString* proj2){
896 wxTextCtrl *itemTextCtrlLeftP;
897 wxTextCtrl *itemTextCtrlRightP;
898 wxTextCtrl *itemTextCtrlRight;
899 wxTextCtrl *itemTextCtrlLeft;
900 wxString *image1_,*image2_,*proj1_,*proj2_;
902 DECLARE_EVENT_TABLE()
903 DECLARE_CLASS( IntroductionFrame )
907 IMPLEMENT_CLASS( IntroductionFrame, wxFrame )
909 BEGIN_EVENT_TABLE(IntroductionFrame, wxDialog)
910 EVT_BUTTON( ID_SELECT_LEFT_IMAGE, IntroductionFrame::OnButtonLeftImage )
911 EVT_BUTTON( ID_SELECT_RIGHT_IMAGE,IntroductionFrame::OnButtonRightImage )
912 EVT_BUTTON( ID_SELECT_LEFT_PROJ, IntroductionFrame::OnButtonLeftProj )
913 EVT_BUTTON( ID_SELECT_RIGHT_PROJ, IntroductionFrame::OnButtonRightProj )
914 EVT_BUTTON( ID_BUTTON_OK, IntroductionFrame::OnButtonOK)
915 EVT_BUTTON( ID_BUTTON_CANCEL, IntroductionFrame::OnButtonCancel)
919 IntroductionFrame(wxFrame* parent,const wxString& title,const wxPoint& pos,const wxSize& size):
920 wxDialog(parent, -1, title, pos, size, wxSTAY_ON_TOP|wxCAPTION|wxRESIZE_BORDER)
923 wxFlexGridSizer* itemFlexGridSizer =
new wxFlexGridSizer(3, 0, 0);
924 this->SetSizer(itemFlexGridSizer);
925 wxSize textSize(370,30);
927 wxStaticText* itemStaticText0 =
928 new wxStaticText(
this, ID_STATIC, wxT(
"First Image"),
929 wxDefaultPosition, wxDefaultSize, 0 );
930 wxButton* itemButtonLeft=
new wxButton(
this, ID_SELECT_LEFT_IMAGE,
931 wxT(
"Select"), wxDefaultPosition,
933 itemTextCtrlLeft =
new wxTextCtrl(
this, ID_TEXT_LEFT_IMAGE,
934 wxT(
""), wxDefaultPosition,
936 itemFlexGridSizer->Add(itemStaticText0, 0,
937 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
939 itemFlexGridSizer->Add(itemTextCtrlLeft, 0,
940 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
942 itemFlexGridSizer->Add(itemButtonLeft, 0,
943 wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
945 wxStaticText* itemStaticText01 =
946 new wxStaticText(
this, ID_STATIC, wxT(
"Projection"),
947 wxDefaultPosition, wxDefaultSize, 0 );
948 wxButton* itemButtonLeftP=
new wxButton(
this, ID_SELECT_LEFT_PROJ,
949 wxT(
"Select"), wxDefaultPosition,
951 itemTextCtrlLeftP =
new wxTextCtrl(
this, ID_TEXT_LEFT_PROJ,
952 wxT(
""), wxDefaultPosition,
954 itemFlexGridSizer->Add(itemStaticText01, 0,
955 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
957 itemFlexGridSizer->Add(itemTextCtrlLeftP, 0,
958 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
960 itemFlexGridSizer->Add(itemButtonLeftP, 0,
961 wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
964 wxStaticText* itemStaticText1 =
965 new wxStaticText(
this, ID_STATIC, wxT(
"Second Image"),
966 wxDefaultPosition, wxDefaultSize, 0 );
967 wxButton* itemButtonRight=
new wxButton(
this, ID_SELECT_RIGHT_IMAGE,
968 wxT(
"Select"), wxDefaultPosition,
970 itemTextCtrlRight=
new wxTextCtrl(
this, ID_TEXT_RIGHT_IMAGE,
971 wxT(
""), wxDefaultPosition,
973 itemFlexGridSizer->Add(itemStaticText1, 0,
974 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
976 itemFlexGridSizer->Add(itemTextCtrlRight, 0,
977 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
979 itemFlexGridSizer->Add(itemButtonRight, 0,
980 wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
982 wxStaticText* itemStaticText02 =
983 new wxStaticText(
this, ID_STATIC, wxT(
"Projection"),
984 wxDefaultPosition, wxDefaultSize, 0 );
985 wxButton* itemButtonRightP=
new wxButton(
this, ID_SELECT_RIGHT_PROJ,
986 wxT(
"Select"), wxDefaultPosition,
988 itemTextCtrlRightP =
new wxTextCtrl(
this, ID_TEXT_RIGHT_PROJ,
989 wxT(
""), wxDefaultPosition,
991 itemFlexGridSizer->Add(itemStaticText02, 0,
992 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
994 itemFlexGridSizer->Add(itemTextCtrlRightP, 0,
995 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
997 itemFlexGridSizer->Add(itemButtonRightP, 0,
998 wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
1000 wxButton* itemButtonOK =
new wxButton(
this, ID_BUTTON_OK, _(
"OK"),
1001 wxDefaultPosition, wxDefaultSize, 0 );
1002 wxButton* itemButtonCancel =
new wxButton(
this, ID_BUTTON_CANCEL, _(
"Cancel"),
1003 wxDefaultPosition, wxDefaultSize, 0 );
1005 itemFlexGridSizer->Add(itemButtonOK, 0,
1006 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
1008 itemFlexGridSizer->Add(itemButtonCancel, 0,
1009 wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL,
1016 void IntroductionFrame::
1017 OnButtonLeftImage( wxCommandEvent& event ){
1019 wxFileDialog dialog(
this,wxT(
"Select Image"),wxT(
""),wxT(
""),
1020 wxT(
"Images (*.mip;*.pgm;*.ppm;*.jpg;*.png)|*.mip;*.pgm;*.ppm;*.jpg;*.png|All files (*.*)|*.*"),
1022 int ret = dialog.ShowModal();
1024 fileName = dialog.GetPath();
1025 itemTextCtrlLeft->SetValue(fileName);
1030 void IntroductionFrame::
1031 OnButtonRightImage( wxCommandEvent& event ){
1033 wxFileDialog dialog(
this,wxT(
"Select Image"),wxT(
""),wxT(
""),
1034 wxT(
"Images (*.mip;*.pgm;*.ppm;*.jpg;*.png)|*.mip;*.pgm;*.ppm;*.jpg;*.png|All files (*.*)|*.*"),
1036 int ret = dialog.ShowModal();
1038 fileName = dialog.GetPath();
1039 itemTextCtrlRight->SetValue(fileName);
1044 void IntroductionFrame::
1045 OnButtonLeftProj( wxCommandEvent& event ){
1047 wxFileDialog dialog(
this,wxT(
"Select Projection"),wxT(
""),wxT(
""),
1048 wxT(
"Projections (*.proj;*.xml)|*.proj;*.xml|All files (*.*)|*.*"),
1050 int ret = dialog.ShowModal();
1052 fileName = dialog.GetPath();
1053 itemTextCtrlLeftP->SetValue(fileName);
1058 void IntroductionFrame::
1059 OnButtonRightProj( wxCommandEvent& event ){
1061 wxFileDialog dialog(
this,wxT(
"Select Projection"),wxT(
""),wxT(
""),
1062 wxT(
"Projections (*.proj;*.xml)|*.proj;*.xml|All files (*.*)|*.*"),
1064 int ret = dialog.ShowModal();
1066 fileName = dialog.GetPath();
1067 itemTextCtrlRightP->SetValue(fileName);
1072 void IntroductionFrame::
1073 OnButtonOK( wxCommandEvent& event ){
1074 *image1_= itemTextCtrlLeft->GetValue();
1075 *image2_= itemTextCtrlRight->GetValue();
1076 *proj1_= itemTextCtrlLeftP->GetValue();
1077 *proj2_ = itemTextCtrlRightP->GetValue();
1081 void IntroductionFrame::
1082 OnButtonCancel( wxCommandEvent& event ){
1089 class BiasShowEpiApp :
public wxApp
1092 virtual bool OnInit();
1096 bool BiasShowEpiApp::OnInit()
1102 bool homographymode =
false;
1103 MainFrame* frame =
new MainFrame();
1105 wxString image1,image2, proj1, proj2;
1106 if (argc == 2 && (strcmp(WxToAscii(argv[1]),
"-h")==0 ||
1107 strcmp(WxToAscii(argv[1]),
"--help")==0 ||
1108 strcmp(WxToAscii(argv[1]),
"/?")==0)) {
1110 #ifdef WIN32 // avoid closing the window
1111 cout<<
"press any key"; _getch();
1122 IntroductionFrame* introframe;
1123 introframe =
new IntroductionFrame(NULL,wxT(
"Select Images and Projections"),wxDefaultPosition,wxSize(600,250));
1124 introframe->SetStrings(&image1,&image2,&proj1, &proj2);
1125 introframe->ShowModal();
1126 fileName[0] = WxToAscii(image1);
1127 fileName[1] = WxToAscii(image2);
1128 projName[0] = WxToAscii(proj1);
1129 projName[1] = WxToAscii(proj2);
1132 fileName[0] = WxToAscii(argv[1]);
1133 fileName[1] = WxToAscii(argv[2]);
1137 for (
int i = 0; i < 2; i++)
1139 projName[i] = WxToAscii(argv[i+3]);
1145 for (
int i = 0; i < 2; i++)
1150 cout <<
"Failed to load image: " << fileName[i] << endl;
1151 #ifdef WIN32 // avoid closing the window
1152 cout<<
"press any key"; _getch();
1156 cout <<
"loaded image, storage type is " << mytmpimg.
GetStorageType() << endl;
1159 if(mytmpFL.GetMaxPixelValue() <= 1.0){
1160 mytmpFL.ScaleShift(255, 1.0);
1168 if(projName[i] !=
""){
1170 if (projection.
Load(projName[i]) != 0)
1172 cout <<
"Failed to load projection:" << projName[i] << endl;
1173 #ifdef WIN32 // avoid closing the window
1174 cout<<
"press any key"; _getch();
1184 for (
int i = 0; i < 2; i++)
1186 if (image[i].IsProjValid())
1190 else if (image[i].IsPValid())
1193 params.
SetP(image[i].GetP());
1194 params.
SetImageSize(image[i].GetWidth(), image[i].GetHeight());
1199 cout <<
"No projection and no P matrix for image: " << fileName[i] << endl;
1200 #ifdef WIN32 // avoid closing the window
1201 cout<<
"press any key"; _getch();
1220 cout <<
"Failed to convert images to RGB" << endl;
1221 #ifdef WIN32 // avoid closing the window
1222 cout<<
"press any key"; _getch();
1230 frame->SetImages(rgbImage[0], proj[0], fileName[0],
1231 rgbImage[1], proj[1], fileName[1], homographymode);
1232 SetTopWindow(frame);
1237 IMPLEMENT_APP(BiasShowEpiApp)
virtual BIAS::KMatrix GetFakeKMatrix(double &imgsize, int resolution=0, const double &maxangle=1.4) const
Returns a fake KMatrix for the camera.
virtual BIAS::Vector3< double > GetC() const
Get projection center.
void Release()
reimplemented from ImageBase
virtual HomgPoint2D ProjectLocal(const Vector3< double > &point, bool IgnoreDistortion=false) const
calculates the projection of a point in the camera coordinate system to a pixel in the image plane of...
int Recalc(unsigned int width, unsigned int height, HomgPoint2D &epipole, enum HomgPoint2D::EPosition epos)
assumes that data_ is already set
virtual void SetPrincipal(const double x, const double y)
Set principal point (in pixels relative to top left corner).
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
enum EPosition DeterminePosition(unsigned int width, unsigned int height)
void BIASGui_EXPORT ConsoleRedirectIO(std::string name=std::string(""))
Extra Console for WIN32 WinMain gui applications.
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual int GetPrincipal(double &PrincipalX, double &PrincipalY) const
Get principal point (in pixels relative to top left corner).
bool IsPositionInImage(const int &x, const int &y) const
check if image contains that pixel position
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
virtual ProjectionParametersBase * Clone() const =0
Covariant virtual copy constructor used in BIAS::Projection.
virtual void Rescale(double ratio, const double offset=0.0)
Adapt internal parameters to resampled image.
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
virtual void SetP(const PMatrix &P)
set from P
unsigned int GetWidth() const
static int CircleCenter(Image< StorageType > &im, unsigned int CenterX, unsigned int CenterY, unsigned int Radius, const StorageType Value[]=NULL)
draws a circular line, either using Value or a good contrast value
virtual void SetQ(const BIAS::Quaternion< double > &Q)
Set orientation from unit quaternion Q.
void CrossProduct(const Vector3< T > &argvec, Vector3< T > &destvec) const
cross product of two vectors destvec = this x argvec
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
Image canvas that does not show zoom frames and redirects mouse click events to its parent...
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
int GetInverse(Matrix3x3< T > &inv) const
Matrix inversion: inverts this and stores resulty in argument inv.
int SetProj(const Projection &Proj)
class representing a Fundamental matrix
unsigned int GetHeight() const
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
virtual bool DoesPointProjectIntoImage(const BIAS::HomgPoint3D &X, BIAS::HomgPoint2D &x, unsigned int cam=0, bool IgnoreDistortion=false) const
Checks if 3D point projects into specified image and returns belonging 2D image point.
virtual BIAS::PMatrix GetP() const
static int RectangleCenter(Image< StorageType > &im, const int x, const int y, const int size, const StorageType value[])
Draws the rectangle around X, Y with Size and Value[i] in channel i.
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
virtual bool Undistort(BIAS::HomgPoint2D &point2d) const
Using the Matlab camera calibration toolbox parameters for an undistortion of distorted coordinates...
enum EColorModel GetColorModel() const
Matrix3x3< T > Transpose() const
returns transposed matrix tested 12.06.2002
static void ProjectEpipolarPlane(const Projection &thisP, Image< PixelType > &thisIm, const Vector3< double > &otherCamCenter, const Vector3< double > &RayDir, PixelType *Color=NULL, int lineWidth=1)
visualize the epipolar plane/line as a curve in the image for any Projection
void UpdateMinZLocal()
run along image border and compute maximum field of view, save in minzlocal
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...
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
describes a projective 3D -> 2D mapping in homogenous coordinates
void SetMetaData(const MetaData &m)
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
const BIAS::Projection & GetProj() const
virtual BIAS::Quaternion< double > GetQ() const
Get orientation as unit quaternion.
Vector3< double > GetC(unsigned int cam=0) const
return Center of camera with index cam.
This is the base class for images in BIAS.
virtual void SetK(const KMatrix &K)
sets the internal parameters from a given KMatrix and updates the cached K and its inverse ...
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.
virtual void SetC(const BIAS::Vector3< double > &C)
Set projection center.
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
class BIASGeometryBase_EXPORT HomgPoint2D
class BIASGeometryBase_EXPORT HomgPoint3D
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...
A class for representing epipolar lines with useful functions like ScanLine().
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase