app-calibrate-VCC4.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "Component/ModelManager.H"
00040 #include "Devices/DeviceOpts.H"
00041 #include "Devices/FrameGrabberConfigurator.H"
00042 #include "Devices/VCC4.H"
00043 #include "GUI/XWinManaged.H"
00044 #include "Image/ColorOps.H"
00045 #include "Image/Image.H"
00046 #include "Image/Pixels.H"
00047 #include "Image/calibrateFunctions.H"
00048 #include "Transport/FrameIstream.H"
00049 #include "Util/log.H"
00050 #include <iostream>
00051 #include <stdio.h>
00052
00053 int main (const int argc, const char **argv)
00054 {
00055 LOG_FLAGS &= (~LOG_FULLTRACE);
00056
00057
00058 ModelManager manager("Camera Calibrator");
00059
00060
00061 nub::soft_ref<FrameGrabberConfigurator>
00062 gbc(new FrameGrabberConfigurator(manager));
00063 manager.addSubComponent(gbc);
00064
00065 nub::soft_ref<VCC4> pantilt(new VCC4(manager));
00066 manager.addSubComponent(pantilt);
00067
00068
00069
00070
00071 manager.setOptionValString(&OPT_FrameGrabberType, "V4L");
00072 manager.setOptionValString(&OPT_FrameGrabberDims, "640x480");
00073
00074
00075 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00076
00077
00078 nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00079 if (gb.isInvalid())
00080 LFATAL("You need to select a frame grabber type via the "
00081 "--fg-type=XX command-line option for this program "
00082 "to be useful");
00083
00084
00085 manager.start();
00086
00087 int maxtilt = 30;
00088 int maxpan = 100;
00089 const Dims dims = gb->peekDims();
00090
00091 Image< PixRGB<byte> > cimg(dims,NO_INIT);
00092 Image<byte> bimg1(dims,NO_INIT), bimg2(dims,NO_INIT);
00093
00094 pantilt->CameraInitialize(true);
00095 pantilt->gotoPosition(0,0,true);
00096
00097 cimg = gb->readRGB();
00098 cimg = gb->readRGB();
00099 cimg = gb->readRGB();
00100
00101 bimg1 = luminance(cimg);
00102
00103 XWinManaged win1(dims,-1,-1,"Center"), win2(dims,-1,-1,"Periphery");
00104 win1.drawImage(bimg1);
00105
00106 int dist = 0, angle = 0;
00107 int lbound = -10, ubound = 10;
00108 int est_pan = 100;
00109 int est_tilt = 80;
00110 float bounds = 0.1;
00111 int est;
00112
00113 std::cout << "Tilt:\n";
00114 while ((dist < 0.9 * dims.h()) && (angle <= maxtilt))
00115 {
00116 cimg = gb->readRGB();
00117 angle++;
00118 pantilt->gotoPosition(0,angle,true);usleep(50000);
00119
00120 bimg2 = luminance(cimg);
00121 win2.drawImage(bimg2);
00122
00123 dist = findAlign(bimg1,bimg2,ALIGN_Y,lbound,ubound);
00124
00125 est = dims.h() / est_tilt * angle;
00126 lbound = (int)(est * (1.0 - bounds));
00127
00128 ubound = (int)(est * (1.0 + bounds));
00129
00130
00131
00132 if ((ubound - lbound) < 10)
00133 {
00134 ubound += 5;
00135 lbound -= 5;
00136 }
00137 if (ubound >= dims.h()) ubound = dims.h() - 1;
00138
00139 std::cout << angle-1 << "\t" << dist << "\n";
00140
00141 }
00142 pantilt->gotoPosition(0,0,true);
00143
00144 std::cout << "\n";
00145
00146 dist = 0; angle = 0;
00147 lbound = -10; ubound = 10;
00148
00149 std::cout << "Pan:\n";
00150 while ((dist < 0.9 * dims.w()) && (angle <= maxpan))
00151 {
00152 cimg = gb->readRGB();
00153 angle++;
00154 pantilt->gotoPosition(angle,0,true);usleep(50000);
00155
00156 bimg2 = luminance(cimg);
00157 win2.drawImage(bimg2);
00158
00159 dist = findAlign(bimg1,bimg2,ALIGN_X,lbound,ubound);
00160
00161 est = dims.w() / est_pan * angle;
00162 lbound = (int)(est * (1.0 - bounds));
00163
00164 ubound = (int)(est * (1.0 + bounds));
00165
00166
00167
00168 if ((ubound - lbound) < 10)
00169 {
00170 ubound += 5;
00171 lbound -= 5;
00172 }
00173 if (ubound >= dims.w()) ubound = dims.w() - 1;
00174
00175
00176 std::cout << angle-1 << "\t" << dist << "\n";
00177
00178 }
00179
00180 std::cout << "\n";
00181
00182 pantilt->gotoPosition(0,0,false);
00183
00184
00185
00186
00187 manager.stop();
00188
00189
00190 return 0;
00191 }
00192
00193
00194
00195
00196
00197