#include <Image/Camera.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/ImageUtils/ImageDraw.hh>
#include <Base/Image/ImageIO.hh>
#include <VideoSource/VideoSource_DCAM.hh>
#include <Gui/GuiCV.hh>
#ifdef WIN32
# include<Base/Common/getopt_W32.h>
#else
# include <unistd.h>
# include <getopt.h>
#endif
using namespace BIAS;
using namespace std;
#define StorageType unsigned char
#include <Base/Debug/TimeMeasure.hh>
float rgain=-31.0/32.0, bgain=31.0/32.0;
float gain = 0.0;
unsigned savecounter=0;
{
bool done = false;
char c;
char title[100];
struct timeval now;
float fps;
int i;
long start=0, end;
bool color, pause, slowconversion=false, autosave=false;
ostringstream os;
sprintf(title,"MyWindow");
pause = false;
color = true;
i = 1;
bool save;
while (!done){
save = false;
gettimeofday(&now, NULL);
end = start;
start = (now.tv_sec % 1000) * 1000 + (now.tv_usec / 1000);
fps = 1.0f / (float)(start-end) * 1000.0f;
switch (c) {
case 'q':
case 27:
done = true;
break;
case 'g':
cam->
AutoMode(DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_AUTO);
cerr << "\nauto gain on"<<endl;
break;
case '1':
cout <<endl<<
"Shutter: "<<cam->
GetShutter()<<endl;
break;
case 'w':
cerr << "\nwhite balance"<<endl;
break;
case 'S':
case ' ':
save = true;
break;
case 's':
autosave=!autosave;
if (autosave)
cerr << "\nstarted saving sequence at frame "<<i<<" into frame"
<<setfill('0')<<setw(5)<<savecounter<<".mip"<<endl;
else
cerr << "\nstopped saving sequence at frame "<<i<<" into frame"
<<setfill('0')<<setw(5)<<savecounter<<".mip"<<endl;
break;
case 'p':
pause = !pause;
break;
case 'c':
color = !color;
if (color) cerr << "\nshowing color image" << endl;
else cerr << "\nshowing grey image" << endl;
break;
case 'G':
cam->
AutoMode(DC1394_FEATURE_GAIN,DC1394_FEATURE_MODE_MANUAL);
cerr << "\nauto gain off"<<endl;
break;
case 'e':
slowconversion=!slowconversion;
if (slowconversion) CamWin.
SetTitle(
"doing slow conversion");
else CamWin.
SetTitle(
"doing fast conversion");
break;
case '7':
bgain-=1.0/32.0;
BIASERR("error setting white balance");}
cerr <<"\nblue gain = "<<bgain<<endl;
break;
case '8':
bgain+=1.0/32.0;
BIASERR("error setting white balance");}
cerr <<"\nblue gain = "<<bgain<<endl;
break;
case '4':
rgain-=1.0/32.0;
BIASERR("error setting white balance");}
cerr <<"\nred gain = "<<rgain<<endl;
break;
case '5':
rgain+=1.0/32.0;
BIASERR("error setting white balance");}
cerr <<"\nred gain = "<<rgain<<endl;
break;
case '[':
gain -= 1.0/32.0;
cout<<"Overall gain :"<<gain<<endl;
break;
case ']':
gain += 1.0/32.0;
cout<<"Overall gain :"<<gain<<endl;
break;
default:
if (c!=-1) cerr <<"unknown key "<<c<<endl;
break;
}
if (!pause) {
cout<<"GrabNextImage"<<endl;
cout<<"GrabNextImage done"<<endl;
if (color) {
cout<<"Color"<<endl;
if (slowconversion){
}
} else {
}
}
else
{
cout<<"B/W"<<endl;
}
if (save) {
os.str("");
os << "frame" << setfill('0') << setw(5) << savecounter;
pic2,
true)!=0){
BIASERR("error saving frame "<<i<<" at file "<<os.str()<<".mip");
}
cerr << "\nsaved frame "<<i<<" in "<<os.str()<<endl;
save = false;
savecounter++;
}
if (autosave){
os.str("");
os << "frame" << setfill('0') << setw(5) << savecounter;
pic2,
true)!=0){
BIASERR("error saving frame "<<i<<" at file "<<os.str()<<".mip");
}
savecounter++;
}
cout <<"Frame: "<<i<<" Showing fps: "<<fps<<"\r";
cout.flush();
i++;
}
}
}
int main(int argc, char *argv[])
{
int res = -1;
cout <<"Openresult: "<<res<<endl;
if (res <0) {
cerr<<" Can not open camera. res="<<res<<endl;
exit(1);
}
cout <<" g : Auto Gain ON\n";
cout <<" G : Auto Gain OFF\n";
cout <<"123 : Gamma mode"<<endl;
cout <<" w : OnePushWhitebalance (not for PointGrey DragonFly)\n";
cout <<" 7/8: decr/incr blue gain (for white balancing manual)\n";
cout <<" 4/5: decr/incr red gain (for white balancing manual)\n";
cout <<" c : Color/Grey \n";
cout <<"SPC : save an image \n";
cout <<" s : save sequence\n";
cout <<" p : Stop/Resume\n";
cout <<" e : toggle between fast and normal conversion\n";
cout <<" q : Quit \n";
mainloop(cam );
delete cam;
return 0;
}