00001 #ifndef PREVIEW_H
00002 #define PREVIEW_H
00003
00004 #include "output.h"
00005 #include "../recognition/imagesource.h"
00006 #include "../recognition/videodevice.h"
00007 #include <iostream>
00008
00009 extern "C"
00010 {
00011 #include <opencv/highgui.h>
00012 }
00013
00014 using namespace std;
00015
00016 namespace seemicro
00017 {
00018
00019 class PreviewOutput : public OutputModule
00020 {
00021 static PreviewOutput *home;
00022 CvFont *font;
00023 int colour, hue, brightness, contrast, whiteness;
00024 public:
00025 ImageSource *src;
00026 PreviewOutput(ImageSource *As, CvFont *Af) : font(Af), src(As)
00027 {
00028 home = this;
00029 if(1 != cvNamedWindow("Preview", 1))
00030 { cerr << "cvNamedWindow(Preview): error" << endl; exit(1); }
00031 try
00032 {
00033 videoDevice& v = dynamic_cast<videoDevice&>(*src);
00034 getPict(v);
00035 cvCreateTrackbar("Keyframerate", "Preview", &v.keyFrameRate, 100, callback);
00036 cvCreateTrackbar("Farbkontrast", "Preview", &colour, 65535, callback);
00037 cvCreateTrackbar("Helligkeit", "Preview", &hue, 65535, callback);
00038 cvCreateTrackbar("Kontrast", "Preview", &brightness, 65535, callback);
00039 cvCreateTrackbar("Weißpunkt", "Preview", &contrast, 65535, callback);
00040 cvCreateTrackbar("Farbkontrast", "Preview", &whiteness, 65535, callback);
00041 }
00042 catch(bad_cast)
00043 {
00044
00045 }
00046 }
00047
00048 ~PreviewOutput()
00049 {
00050 cvDestroyWindow("Preview");
00051 }
00052
00053 void getPict(videoDevice& v)
00054 {
00055 colour = v.pict.colour;
00056 hue = v.pict.hue;
00057 brightness = v.pict.brightness;
00058 contrast = v.pict.contrast;
00059 whiteness = v.pict.whiteness;
00060 }
00061
00062 void setPict(videoDevice& v)
00063 {
00064 v.pict.colour = colour;
00065 v.pict.hue = hue;
00066 v.pict.brightness = brightness;
00067 v.pict.contrast = contrast;
00068 v.pict.whiteness = whiteness;
00069 v.setPicture(NULL);
00070 }
00071
00072 static void callback(int dummy=0)
00073 {
00074 if(!home) return;
00075 try
00076 {
00077 videoDevice& v = dynamic_cast<videoDevice&>(*home->src);
00078 home->setPict(v);
00079 if(v.keyFrameRate <= 0) v.keyFrameRate=1;
00080 }
00081 catch(bad_cast)
00082 {
00083
00084 }
00085 }
00086
00087 virtual void output(bool keyframe)
00088 {
00089 try
00090 {
00091 videoDevice& vdev = dynamic_cast<videoDevice&>(*src);
00092 double frate = vdev.framerate();
00093 if(keyframe)
00094 {
00095 char line[50];
00096 sprintf(line, "%2.1f Bilder/s", frate);
00097 cvPutText(src->img, line, cvPoint(src->img->width-100, 30), font,
00098 CV_RGB(255, 255, 255));
00099 }
00100 }
00101 catch(bad_cast)
00102 {
00103
00104 }
00105 if(keyframe)
00106 {
00107 cvShowImage("Preview", src->img);
00108 cvResizeWindow("Preview", src->img->width+15, src->img->height+250);
00109 }
00110 }
00111
00112 };
00113
00114 }
00115
00116 #endif
00117