• 大小: 11MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-06
  • 语言: 其他
  • 标签: opencv  金字塔  

资源简介

在网上找了好久都没找到基于opencv的金字塔模板匹配算法代码,我就自己把金字塔和模板匹配的代码结合了一下,代码基于opencv2.48.

资源截图

代码片段和文件信息

//-----------------------------------【头文件包含部分】---------------------------------------  
//      描述:包含程序所依赖的头文件  
//----------------------------------------------------------------------------------------------   
#include   
#include   
#include “opencv2/highgui/highgui.hpp“
#include 
#include 
#include 
#include se.h>
#include 
//全局变量

//-----------------------------------【命名空间声明部分】---------------------------------------  
//      描述:包含程序所使用的命名空间  
//-----------------------------------------------------------------------------------------------   
using namespace cv;
using namespace std;

//全局变量
/*
Mat srcImage;//源图
Mat tmpImage;//源模板

*/
Mat dstImage1;//目标图1
Mat dstImage2;//目标图2  
Mat resultImg; //匹配结果图像
Mat srcImg; //原始图像
Mat templImg; //模板图像
Mat srcImage1;//源图临时变量
Mat tmpImage1;//模板图临时变量

const char* imageWindow = “Source Image“; //原始图像显示窗口
const char* resultWindow = “Result Window“; //匹配结果图像显示窗口

int matchMethod; //匹配方法index
int maxTrackbar = 5; //滑动条范围(与匹配方法个数对应)

/// 函数声明 ///
void MatchingMethod(int void*); //匹配函数
//-----------------------------------【main( )函数】--------------------------------------------  
//      描述:控制台应用程序的入口函数,我们的程序从这里开始  
//-----------------------------------------------------------------------------------------------  
int main()
{     
double i kr;
// 加载原始图像和模板图像
srcImg = imread(“yuan.png“ 1);
templImg = imread(“muban.png“ 1);
srcImage1 = srcImg;
tmpImage1 = templImg;
// 创建显示窗口
namedWindow(imageWindow CV_WINDOW_AUTOSIZE);
namedWindow(resultWindow CV_WINDOW_AUTOSIZE);

// 创建滑动条
char* trackbarLabel =
“Method: \n \
  0: SQDIFF \n \
        1: SQDIFF NORMED \n \
        2: TM CCORR \n \
        3: TM CCORR NORMED \n \
        4: TM COEFF \n \
        5: TM COEFF NORMED“;
//参数:滑动条名称 显示窗口名称 匹配方法index 滑动条范围 回调函数
createTrackbar(trackbarLabel imageWindow &matchMethod maxTrackbar MatchingMethod);


i=GetTickCount();
//进行向下取样操作  
pyrDown(srcImage1 dstImage1 Size(srcImage1.cols / 2 srcImage1.rows / 2));
pyrDown(tmpImage1 dstImage2 Size(tmpImage1.cols / 2 tmpImage1.rows / 2));


MatchingMethod(0 0);
k = GetTickCount();
r = k - i;
// cout << r << endl;

waitKey(0);

return 0;
}

/// 函数定义 ///
void MatchingMethod(int void*) //匹配函数
{
Mat imageROI;
// 深拷贝用于显示
Mat displayImg;
dstImage1.copyTo(displayImg);


// 创建匹配结果图像,为每个模板位置存储匹配结果
// 匹配结果图像大小为:(W-w+1)*(H-h+1)
int result_cols = dstImage1.cols - dstImage2.cols + 1;
int result_rows = dstImage1.rows - dstImage2.rows + 1;
resultImg.create(result_cols result_rows CV_32FC1);

// 进行匹配并归一化
matchTemplate(dstImage1 dstImage2 resultImg matchMethod);
normalize(resultImg resultImg 0 1 NORM_MINMAX -1 Mat());

// 使用minMaxLoc找出最佳匹配

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

     文件      74240  2015-07-09 15:24  金字塔\Debug\金字塔.exe

     文件     728392  2015-07-09 15:24  金字塔\Debug\金字塔.ilk

     文件    2173952  2015-07-09 15:24  金字塔\Debug\金字塔.pdb

     文件          0  2015-07-09 15:27  金字塔\oleaut32.pdb\7B8A484D32F449DC99F82BF27DDD65E62\oleaut32.pd_

     文件    1092608  2015-07-09 15:24  金字塔\金字塔\Debug\vc120.idb

     文件    1585152  2015-07-09 15:24  金字塔\金字塔\Debug\vc120.pdb

     文件     262584  2015-07-09 15:24  金字塔\金字塔\Debug\源.obj

     文件       2209  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.log

     文件        580  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.tlog\cl.command.1.tlog

     文件      35486  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.tlog\CL.read.1.tlog

     文件        352  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.tlog\CL.write.1.tlog

     文件       2664  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.tlog\link.command.1.tlog

     文件       7478  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.tlog\link.read.1.tlog

     文件        336  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.tlog\link.write.1.tlog

     文件        165  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.tlog\金字塔.lastbuildstate

     文件      17996  2015-05-18 17:04  金字塔\金字塔\muban.png

     文件     132922  2015-05-18 17:03  金字塔\金字塔\yuan.png

     文件       4448  2015-06-14 22:59  金字塔\金字塔\源.cpp

     文件       4085  2015-05-18 11:06  金字塔\金字塔\金字塔.vcxproj

     文件        944  2015-05-18 11:06  金字塔\金字塔\金字塔.vcxproj.filters

     文件   48955392  2015-07-09 15:28  金字塔\金字塔.sdf

     文件        973  2015-05-18 09:12  金字塔\金字塔.sln

    ..A..H.     26112  2015-07-09 15:28  金字塔\金字塔.v12.suo

     目录          0  2015-07-09 15:24  金字塔\金字塔\Debug\金字塔.tlog

     目录          0  2015-07-09 15:27  金字塔\oleaut32.pdb\7B8A484D32F449DC99F82BF27DDD65E62

     目录          0  2015-07-09 15:24  金字塔\金字塔\Debug

     目录          0  2015-05-18 17:26  金字塔\Debug

     目录          0  2015-07-09 15:27  金字塔\oleaut32.pdb

     目录          0  2015-07-09 15:31  金字塔\金字塔

     目录          0  2015-07-09 15:28  金字塔

............此处省略3个文件信息

评论

共有 条评论