Hauptseite | Liste aller Namensbereiche | Klassenhierarchie | Alphabetische Liste | Übersicht | Auflistung der Dateien | Elemente eines Namensbereiches | Datenstruktur-Elemente | Datei-Elemente

polar.h

gehe zur Dokumentation dieser Datei
00001 #ifndef POLARMODULE_H
00002 #define POLARMODULE_H
00003 
00004 #include "imagesource.h"
00005 #include "../micro.h"
00006 extern "C"
00007 {
00008   #include <opencv/highgui.h>
00009 }
00010 
00011 namespace seemicro
00012 {
00013 
00014 inline uchar getInterpolated8u_1(IplImage *img, float xf, float yf)
00015 {
00016   float dx = xf-int(xf);
00017   float dy = yf-int(yf);
00018   assert(dx>=0);
00019   assert(dx<1);
00020 
00021   uchar p01 = getPixel8u_1(img, int(xf)  , int(yf)  );
00022   uchar p00 = getPixel8u_1(img, int(xf)+1, int(yf)  );
00023   uchar p11 = getPixel8u_1(img, int(xf)  , int(yf)+1);
00024   uchar p10 = getPixel8u_1(img, int(xf)+1, int(yf)+1);
00025 
00026   uchar i = uchar( (1-dy)*(1-dx)*p00 + (1-dy)*dx*p10 + dy*(1-dx)*p01 + dx*dy*p11 );
00027 
00028   return i;
00029 }
00030 
00036 struct PolarModule : public ImageSource
00037 {
00038   ImageSource& src;
00039   Micro& m;
00040 
00041   PolarModule(ImageSource& As, Micro& Am, int resTheta, int resRho) : src(As), m(Am)
00042   {
00043     img = cvCreateImage(cvSize(resTheta, resRho), IPL_DEPTH_8U, src.img->nChannels);
00044   }
00045 
00046   ~PolarModule()
00047   {
00048     cvReleaseImage(&img);
00049   }
00050 
00051   void processFrame(myrect *ROI=NULL)
00052   {
00053     // we need our own ROI coz can't live with keyframes
00054 
00055     // ROI bezieht sich auf das Eingabebild
00056     myrect ROI2 = myrect(
00057         int(m.mitte.p.x-m.radius), int(m.mitte.p.y-m.radius),
00058         int(2*m.radius), int(2*m.radius) );
00059 
00060     // auch vom Ausgabebild kann der Ausschnitt begrenzt werden
00061     float thetaStart = 0;
00062     float thetaEnd = 2*M_PI;
00063     float thetaStep = (thetaEnd-thetaStart) / img->width;
00064 
00065     float rhoStart = 0.01;
00066     float rhoEnd = 1;
00067     float rhoStep = (rhoEnd-rhoStart) / img->height;
00068 
00069     if(img->nChannels != 1 && img->nChannels != 3)
00070     {
00071       cerr << "Image format unsupported (nChannels must be 1 or 3).\n";
00072       return;
00073     }
00074 
00075     for(int r=0; r<img->width; r++)
00076       for(int t=0; t<img->height ; t++)
00077       {
00078         float theta = thetaStart + float(t)*thetaStep;
00079         float rho = rhoStart + float(r)*rhoStep;
00080         float xf = ROI2.r.x + ROI2.r.width/2. + rho*cos(theta)*ROI2.r.width/2.;// elliptic...
00081         float yf = ROI2.r.y + ROI2.r.height/2. + rho*sin(theta)*ROI2.r.height/2.;
00082 
00083         // TODO "if" für jedes pixel = langsam
00084         if(img->nChannels==1)
00085           //putPixel8u_1(img, t, r, getInterpolated8u_1(src.img, xf, yf));
00086           putPixel8u_1(img, t, r, getPixel8u_1(src.img, int(xf), int(yf)));
00087         else
00088           putPixel8u_3(img, t, r, getPixel8u_3(src.img, int(xf), int(yf)));
00089       }
00090 
00091 //cvSmooth(img, img, CV_GAUSSIAN, 3, 3);
00092 #ifdef DEBUG
00093     if(DEBUGLEVEL>=3) cerr << "<-PolarModule::processFrame()\n";
00094 #endif
00095   }
00096 
00097   void processKeyFrame(void)
00098   {
00099 #ifdef DEBUG
00100     if(DEBUGLEVEL>=3) cerr << "->PolarModule::processKeyFrame()\n";
00101 #endif
00102     processFrame();
00103   }
00104 
00105 }; // PolarModule
00106 
00107 } // seemicro
00108 
00109 #endif // POLARMODULE_H

Erzeugt am Sun Oct 3 12:52:47 2004 für seemicro von doxygen 1.3.2