// code
#include <QtGui>
#include <math.h>
#include <stdlib.h>
#include "OpenCVwarpFilter.h"
//
#include "cv.h"
#include "cxcore.h"
#pragma message("automatic link to OpenCV libs")
#pragma comment(lib,"cv210.lib")
#pragma comment(lib,"cxcore210.lib")
struct OpenCVStruct
{
int iWidth;
int iHeight;
IplImage *m_pImg; // OpenCV Images
IplImage *m_pOutputImg;
CvMat *m_pMapMatrix; // OpenCV Matrix
CvPoint2D32f src_quad[4];
CvPoint2D32f dst_quad[4];
};
QString OpenCVwarpFilterPlugin
::filterName() const {
return "piWarp_OpenCV";
}
unsigned long OpenCVwarpFilterPlugin::filterParamsSize() const
{
return sizeof(OpenCVStruct);
}
void OpenCVwarpFilterPlugin::filterInit(void* piParams)
{
OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
pOpenCV->m_pImg = NULL;
pOpenCV->m_pOutputImg = NULL;
pOpenCV->m_pMapMatrix = NULL;
pOpenCV->iWidth = 0;
pOpenCV->iHeight = 0;
}
void OpenCVwarpFilterPlugin::filterClose(void* piParams)
{
OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
if (pOpenCV->m_pImg != NULL)
{
cvReleaseImage(&pOpenCV->m_pImg);
cvReleaseImage(&pOpenCV->m_pOutputImg);
cvReleaseMat(&pOpenCV->m_pMapMatrix);
}
}
void OpenCVwarpFilterPlugin::setOperation(unsigned char *destintation,unsigned char *source,
long width,long height,long dest_pitch,long src_pitch,long Bpp,void* piParams)
{
OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
if (! pOpenCV)
return;
if ((pOpenCV->m_pImg == NULL) || (pOpenCV->iWidth != width) || (pOpenCV->iHeight != height))
{
if (pOpenCV->m_pImg != NULL)
{
cvReleaseImage(&pOpenCV->m_pImg);
cvReleaseImage(&pOpenCV->m_pOutputImg);
cvReleaseMat(&pOpenCV->m_pMapMatrix);
}
pOpenCV->m_pImg = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, 3);
pOpenCV->m_pOutputImg = cvCreateImage(cvGetSize(pOpenCV->m_pImg), 8, 3 );
pOpenCV->src_quad[0].x = 150; pOpenCV->src_quad[0].y = 150;
pOpenCV->src_quad[1].x = 0; pOpenCV->src_quad[1].y = (float)height;
pOpenCV->src_quad[2].x = (float)width; pOpenCV->src_quad[2].y = 0;
pOpenCV->src_quad[3].x = (float)width; pOpenCV->src_quad[3].y = (float)height;
pOpenCV->dst_quad[0].x = 0; pOpenCV->dst_quad[0].y = 0;
pOpenCV->dst_quad[1].x = 0; pOpenCV->dst_quad[1].y = (float)height;
pOpenCV->dst_quad[2].x = (float)width; pOpenCV->dst_quad[2].y = 0;
pOpenCV->dst_quad[3].x = (float)width; pOpenCV->dst_quad[3].y = (float)height;
pOpenCV->m_pMapMatrix = cvCreateMat(3,3,CV_32FC1);
}
pOpenCV->iWidth = width;
pOpenCV->iHeight = height;
cvWarpPerspectiveQMatrix(pOpenCV->src_quad, pOpenCV->dst_quad, pOpenCV->m_pMapMatrix);
memcpy(pOpenCV->m_pImg->imageData,source,pOpenCV->m_pImg->imageSize);
cvWarpPerspective(pOpenCV->m_pImg, pOpenCV->m_pOutputImg, pOpenCV->m_pMapMatrix, CV_WARP_FILL_OUTLIERS, cvScalarAll(1));
memcpy(destintation,pOpenCV->m_pOutputImg->imageData,pOpenCV->m_pOutputImg->imageSize);
}
Q_EXPORT_PLUGIN2(FilterInterface, OpenCVwarpFilterPlugin)
// Header
#ifndef EXTRAFILTERSPLUGIN_H
#define EXTRAFILTERSPLUGIN_H
#include <QObject>
#include <QString>
#include "interfaceImageFilter.h"
class OpenCVwarpFilterPlugin
: public QObject,
public FilterInterface
{
Q_OBJECT
Q_INTERFACES(FilterInterface)
public:
unsigned long filterParamsSize() const;
void filterInit(void* piParams);
void filterClose(void* piParams);
void setOperation(unsigned char *dest,unsigned char *src,
long width,long height,long dest_pitch,long src_pitch,long Bpp,void* piParams);
};
#endif
// code
#include <QtGui>
#include <math.h>
#include <stdlib.h>
#include "OpenCVwarpFilter.h"
//
#include "cv.h"
#include "cxcore.h"
#pragma message("automatic link to OpenCV libs")
#pragma comment(lib,"cv210.lib")
#pragma comment(lib,"cxcore210.lib")
struct OpenCVStruct
{
int iWidth;
int iHeight;
IplImage *m_pImg; // OpenCV Images
IplImage *m_pOutputImg;
CvMat *m_pMapMatrix; // OpenCV Matrix
CvPoint2D32f src_quad[4];
CvPoint2D32f dst_quad[4];
};
QString OpenCVwarpFilterPlugin::filterName() const
{
return "piWarp_OpenCV";
}
unsigned long OpenCVwarpFilterPlugin::filterParamsSize() const
{
return sizeof(OpenCVStruct);
}
void OpenCVwarpFilterPlugin::filterInit(void* piParams)
{
OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
pOpenCV->m_pImg = NULL;
pOpenCV->m_pOutputImg = NULL;
pOpenCV->m_pMapMatrix = NULL;
pOpenCV->iWidth = 0;
pOpenCV->iHeight = 0;
}
void OpenCVwarpFilterPlugin::filterClose(void* piParams)
{
OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
if (pOpenCV->m_pImg != NULL)
{
cvReleaseImage(&pOpenCV->m_pImg);
cvReleaseImage(&pOpenCV->m_pOutputImg);
cvReleaseMat(&pOpenCV->m_pMapMatrix);
}
}
void OpenCVwarpFilterPlugin::setOperation(unsigned char *destintation,unsigned char *source,
long width,long height,long dest_pitch,long src_pitch,long Bpp,void* piParams)
{
OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
if (! pOpenCV)
return;
if ((pOpenCV->m_pImg == NULL) || (pOpenCV->iWidth != width) || (pOpenCV->iHeight != height))
{
if (pOpenCV->m_pImg != NULL)
{
cvReleaseImage(&pOpenCV->m_pImg);
cvReleaseImage(&pOpenCV->m_pOutputImg);
cvReleaseMat(&pOpenCV->m_pMapMatrix);
}
pOpenCV->m_pImg = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, 3);
pOpenCV->m_pOutputImg = cvCreateImage(cvGetSize(pOpenCV->m_pImg), 8, 3 );
pOpenCV->src_quad[0].x = 150; pOpenCV->src_quad[0].y = 150;
pOpenCV->src_quad[1].x = 0; pOpenCV->src_quad[1].y = (float)height;
pOpenCV->src_quad[2].x = (float)width; pOpenCV->src_quad[2].y = 0;
pOpenCV->src_quad[3].x = (float)width; pOpenCV->src_quad[3].y = (float)height;
pOpenCV->dst_quad[0].x = 0; pOpenCV->dst_quad[0].y = 0;
pOpenCV->dst_quad[1].x = 0; pOpenCV->dst_quad[1].y = (float)height;
pOpenCV->dst_quad[2].x = (float)width; pOpenCV->dst_quad[2].y = 0;
pOpenCV->dst_quad[3].x = (float)width; pOpenCV->dst_quad[3].y = (float)height;
pOpenCV->m_pMapMatrix = cvCreateMat(3,3,CV_32FC1);
}
pOpenCV->iWidth = width;
pOpenCV->iHeight = height;
cvWarpPerspectiveQMatrix(pOpenCV->src_quad, pOpenCV->dst_quad, pOpenCV->m_pMapMatrix);
memcpy(pOpenCV->m_pImg->imageData,source,pOpenCV->m_pImg->imageSize);
cvWarpPerspective(pOpenCV->m_pImg, pOpenCV->m_pOutputImg, pOpenCV->m_pMapMatrix, CV_WARP_FILL_OUTLIERS, cvScalarAll(1));
memcpy(destintation,pOpenCV->m_pOutputImg->imageData,pOpenCV->m_pOutputImg->imageSize);
}
Q_EXPORT_PLUGIN2(FilterInterface, OpenCVwarpFilterPlugin)
// Header
#ifndef EXTRAFILTERSPLUGIN_H
#define EXTRAFILTERSPLUGIN_H
#include <QObject>
#include <QString>
#include "interfaceImageFilter.h"
class OpenCVwarpFilterPlugin : public QObject, public FilterInterface
{
Q_OBJECT
Q_INTERFACES(FilterInterface)
public:
QString filterName() const;
unsigned long filterParamsSize() const;
void filterInit(void* piParams);
void filterClose(void* piParams);
void setOperation(unsigned char *dest,unsigned char *src,
long width,long height,long dest_pitch,long src_pitch,long Bpp,void* piParams);
};
#endif
To copy to clipboard, switch view to plain text mode
Bookmarks