资源简介

OpenCV实现相位相关图像配准,编译产生库文件

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “ImageProcessing.h“
#include “stdio.h“

/************************************************************************/
/* 图像傅里叶变换                                                       */
/************************************************************************/
void FFT_2D(IplImage * src CvMat * dst)
{
CvMat * real = cvCreateMat(dst->rows dst->cols CV_64FC1);
CvMat * imag = cvCreateMat(dst->rows dst->cols CV_64FC1);
CvMat * cplx = cvCreateMat(dst->rows dst->cols CV_64FC2);
CvMat temp;

cvGetSubRect(real &temp cvRect(00 src->width src->height));
cvScale(src &temp 1.0 0.0);

if (dst->cols > src->width)
{
cvGetSubRect(real &temp cvRect(src->width 0 dst->cols - src->width src->height));
cvZero(&temp);
}

cvZero(imag);
cvMerge(real imag NULL NULL cplx);

cvReleaseMat(&real);
cvReleaseMat(&imag);

cvDFT(cplx dst CV_DXT_FORWARD src->height);

cvReleaseMat(&cplx);
}

/************************************************************************/
/* 相位相关的图像配准                                                   */
/************************************************************************/
BOOL MethodPhaseCorrelation(IplImage * image1 IplImage * image2 int & iOffX int & iOffY)
{
int iDftX = image1->width;
int iDftY = image1->height;

CvMat * mat1 = cvCreateMat(iDftY iDftX CV_64FC2);
CvMat * mat2 = cvCreateMat(iDftY iDftX CV_64FC2);

FFT_2D(image1 mat1);
FFT_2D(image2 mat2);

cvMulSpectrums(mat1 mat2 mat1 CV_DXT_MUL_CONJ);

for (int i = 0; i < iDftY; i++)
for (int j = 0; j < iDftX; j++)
{
double & re = ((double*)(mat1->data.ptr + mat1->step * i))[j * 2];
double & im = ((double*)(mat1->data.ptr + mat1->step * i))[j * 2 + 1];
double norm = sqrt(re * re + im * im);

re /= norm;
im /= norm;
}
cvDFT(mat1 mat1 CV_DXT_INV_SCALE mat1->rows);

double fMax = -DBL_MAX;

for (int i = 0; i < iDftY; i++)
for (int j = 0; j < iDftX; j++)
{
double re = ((double*)(mat1->data.ptr + mat1->step * i))[j * 2];
if (re > fMax)
{
fMax = re;
iOffX = j;
iOffY = i;
}
}

//  FILE * fp1;
// 
//  fopen_s(&fp1 “data.txt“ “w“);
// 
//  for (int i = 0; i < iDftY; i++)
//  {
//  for (int j = 0; j < iDftX; j++)
//  {
//  double re = ((double*)(mat1->data.ptr + mat1->step * i))[j * 2];
//  double im = ((double*)(mat1->data.ptr + mat1->step * i))[j * 2 + 1];
// 
//  fprintf_s(fp1 “%.4lf\t“ re);
//  }
//  fprintf_s(fp1 “\n“);
//  }
//  fclose(fp1);

cvReleaseMat(&mat1);
cvReleaseMat(&mat2);

return TRUE;
}

/************************************************************************/
/* 图像配准                                                             */
/************************************************************************/
BOOL ImageRegistration(int iMethod IplImage * image1 IplImage * image2 int & iOffX int & iOffY)
{
if (iMeth

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6560  2009-11-05 18:54  Phase Correlation\ImageProcessing\ImageProcessing\Debug\BuildLog.htm

     文件      18546  2009-11-05 18:54  Phase Correlation\ImageProcessing\ImageProcessing\Debug\ImageProcessing.obj

     文件     786432  2009-11-05 18:54  Phase Correlation\ImageProcessing\ImageProcessing\Debug\ImageProcessing.pch

     文件       9687  2009-11-05 18:54  Phase Correlation\ImageProcessing\ImageProcessing\Debug\stdafx.obj

     文件     224256  2009-11-05 18:54  Phase Correlation\ImageProcessing\ImageProcessing\Debug\vc90.idb

     文件     159744  2009-11-05 18:54  Phase Correlation\ImageProcessing\ImageProcessing\Debug\vc90.pdb

     文件       3118  2009-11-05 18:54  Phase Correlation\ImageProcessing\ImageProcessing\ImageProcessing.cpp

     文件       4269  2009-11-05 15:25  Phase Correlation\ImageProcessing\ImageProcessing\ImageProcessing.vcproj

     文件       1377  2009-11-05 18:56  Phase Correlation\ImageProcessing\ImageProcessing\ImageProcessing.vcproj.Ker.Administrator.user

     文件       1258  2009-11-05 14:45  Phase Correlation\ImageProcessing\ImageProcessing\ReadMe.txt

     文件        302  2009-11-05 14:45  Phase Correlation\ImageProcessing\ImageProcessing\stdafx.cpp

     文件        371  2009-11-05 14:45  Phase Correlation\ImageProcessing\ImageProcessing\stdafx.h

     文件        765  2009-11-05 14:45  Phase Correlation\ImageProcessing\ImageProcessing\targetver.h

     文件        911  2009-11-05 14:45  Phase Correlation\ImageProcessing\ImageProcessing.sln

    ..A..H.     18432  2009-11-05 18:56  Phase Correlation\ImageProcessing\ImageProcessing.suo

     文件        617  2009-11-05 16:35  Phase Correlation\Include\ImageProcessing.h

     文件      29008  2009-11-05 18:54  Phase Correlation\Lib\ImageProcessing.lib

     目录          0  2009-11-05 18:57  Phase Correlation\ImageProcessing\ImageProcessing\Debug

     目录          0  2009-11-05 18:57  Phase Correlation\ImageProcessing\ImageProcessing

     目录          0  2009-11-05 18:57  Phase Correlation\ImageProcessing

     目录          0  2009-11-05 18:57  Phase Correlation\Include

     目录          0  2009-11-05 18:57  Phase Correlation\Lib

     目录          0  2009-11-05 18:57  Phase Correlation

----------- ---------  ---------- -----  ----

              1265653                    23


评论

共有 条评论