E:/dev/ssip2006/snake/QtCvWrapper.cpp

Go to the documentation of this file.
00001 // Qt includes
00002 #include <QtGui/QMessageBox>
00003 #include <QtCore/QPoint>
00004 
00005 
00006 // local includes
00007 #include "qtcvwrapper.h"
00008 #include "MainProgram.h"
00009 #include "snake.h"
00010 
00012 QtCvWrapper::QtCvWrapper(MainProgram* parent, MainWindow* gui) :
00013 m_parent(parent),
00014 m_gui(gui),
00015 m_snake(0),
00016 m_iplImg(0),
00017 m_iterate(true),
00018 m_step(false)
00019 {
00020 
00021 }
00022 
00024 QtCvWrapper::~QtCvWrapper(void)
00025 {
00026         if(m_snake)
00027                 delete m_snake;
00028 }
00029 
00032 void QtCvWrapper::slotSnakeButtonPressed()
00033 {
00034         if(!m_snake)
00035                 return;
00036 
00037         IplImage* resultImg = m_snake->iterateSnakeCurve(20, true);
00038 
00039         QImage* convertedImg = new QImage();
00040         convertImage(resultImg, convertedImg);
00041         m_gui->showImage(convertedImg);}
00042 
00044 void QtCvWrapper::createTestImage(CvPoint center, CvSize axes, CvScalar color, CvScalar background)
00045 {
00046         m_iplImg = cvCreateImage( cvSize(512,512), IPL_DEPTH_8U, 1);
00047         cvSet(m_iplImg, background);
00048         cvEllipse( m_iplImg, center, axes, 0, 0, 360, color, -1, 8, 0 );
00049 }
00050 
00051 
00053 void QtCvWrapper::convertImage(IplImage* src, QImage* dest)
00054 {
00055         QString tmpFile = "tmpImg.bmp";
00056         int status = cvSaveImage(tmpFile.toLatin1(), src);
00057         dest->load(tmpFile);    
00058 }
00059 
00061 CvPoint* QtCvWrapper::createEllipse(QPoint ulPt, QPoint lrPt, int numSegments)
00062 {
00063         int width   = lrPt.x() - ulPt.x();
00064         int height  = lrPt.y() - ulPt.y();
00065         CvPoint* pt = new CvPoint[numSegments];
00066         for(int i = 0; i < numSegments; i++)
00067         {
00068                 pt[i].x = cvRound( width * cos(i * 6.28 / numSegments) / 2.0
00069                         + ulPt.x() + (width / 2) );
00070 
00071                 pt[i].y = cvRound( height * sin(i * 6.28 / numSegments) / 2.0
00072                         + ulPt.y() + (height / 2) );
00073         }
00074         return pt;
00075 }
00076 
00079 void QtCvWrapper::slotImageOpened()
00080 {
00081         qDebug(m_gui->getFileName()->toLatin1());
00082         // load image as a grayscale image
00083         m_iplImg = cvLoadImage(m_gui->getFileName()->toLatin1(), 0);
00084 }
00085 
00087 void QtCvWrapper::slotTest()
00088 {
00089         this->createTestImage(cvPoint(256,265), cvSize(100,70), cvRealScalar(140), cvRealScalar(125));
00090         m_snake = new Snake(this, m_iplImg);
00091         m_snake->initSnakeCurve();
00092         IplImage* resultImg = m_snake->iterateSnakeCurve(20, true);
00093 
00094         QImage* convertedImg = new QImage();
00095         convertImage(resultImg, convertedImg);
00096         m_gui->showImage(convertedImg);
00097         delete convertedImg;
00098 }
00099 
00101 void QtCvWrapper::slotInitCurve()
00102 {
00103         if(!m_iplImg)
00104                 return;
00105         qDebug("initSnakeCurve: %d/%d -- %d/%d", m_gui->getULPt().x(), 
00106                 m_gui->getULPt().y(), m_gui->getLRPt().x(), m_gui->getLRPt().y());
00107         CvPoint* ellipse = createEllipse(m_gui->getULPt(), m_gui->getLRPt(), 200);
00108         m_snake = new Snake(this, m_iplImg);
00109         m_snake->initSnakeCurve(ellipse);
00110 
00111         IplImage* snakeImg = m_snake->getSnakeImage();
00112         QImage* convertedImg = new QImage();
00113         convertImage(snakeImg, convertedImg);
00114         m_gui->showImage(convertedImg);
00115         delete convertedImg;
00116 }
00117 
00119 void QtCvWrapper::slotIterationOn()
00120 {
00121         qDebug("iteration on");
00122         m_iterate = true;
00123         m_step    = false;
00124 }
00125 
00127 void QtCvWrapper::slotIterationOff()
00128 {
00129         qDebug("iteration off");
00130         m_iterate = false;
00131         m_step    = false;
00132 
00133 }
00134 
00136 void QtCvWrapper::slotIterationStep()
00137 {
00138         qDebug("iteration step");
00139         m_iterate = true;
00140         m_step    = true;
00141 }
00142 
00143 

Generated on Thu Jul 6 23:16:43 2006 for Snake Ballooning by  doxygen 1.4.7