⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 disparity 200712dlg.cpp

📁 一个基于MFC的SIFT图像配准算法代码。好用
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// disparity 200712Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "disparity 200712.h"
#include "disparity 200712Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDisparity200712Dlg dialog

CDisparity200712Dlg::CDisparity200712Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDisparity200712Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDisparity200712Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDisparity200712Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDisparity200712Dlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDisparity200712Dlg, CDialog)
	//{{AFX_MSG_MAP(CDisparity200712Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDisparity200712Dlg message handlers

BOOL CDisparity200712Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDisparity200712Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CDisparity200712Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDisparity200712Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDisparity200712Dlg::OnButton1() 
{
 cvNamedWindow( "LkDemo2", 1 );
	
}

void CDisparity200712Dlg::OnButton2() 
{
	CImg left,right;
	CDisparity disp;
	IplImage showdisp, showmatch;

	printf("左图像:\n");
	left.CreateImg("1.bmp");		//读取图像
	left.FindKeypoint();						//找特征点
	left.Direction4Kp();						//确定特征点的方向(在这一步中特征点的数量可能会增加)
	left.ConstructDescripter();					//计算特征点的128维特征
	left.DrawKeypoint();						//在图像上画出特征点

	printf("右图像:\n");
	right.CreateImg("2.bmp");
	right.FindKeypoint();
	right.Direction4Kp();
	right.ConstructDescripter();
	right.DrawKeypoint();

	disp.Initialization(left.width, left.height, right.width, right.height);//初始化视差图(因为以左图像为基准,所以视差图的大小与左图像相同)
	disp.SetSeed(left.image32f, left.kp, left.n_kp, right.image32f, right.kp, right.n_kp);
	disp.DrawMatchedKp(left.image_c, right.image_c);

	IplImage	*image1;
	IplImage	*image2;
		IplImage	*image32fl;
	IplImage	*image32fr;
	int width,height;
	image1 = cvLoadImage("1result_segm.jpg", 0);		//强制转换为单色

	width = image1->width;					//保存图像的尺寸
	height = image1->height;

	image32fl = cvCreateImage ( cvSize(width,height), IPL_DEPTH_32F, 1);		

	cvConvert( image1, image32fl);			//转换为32位浮点图像

		image2 = cvLoadImage( "2result_segm.jpg", 0);		//强制转换为单色

	width = image2->width;					//保存图像的尺寸
	height = image2->height;

	image32fr = cvCreateImage ( cvSize(width,height), IPL_DEPTH_32F, 1);		

	cvConvert( image2, image32fr);			//转换为32位浮点图像

	
	
 	disp.Propagation(image32fl, image32fr);

 //	cvShowManyImages("原图", 2, left.image_c, right.image_c);

	left.ShowImg("左图像");
	right.ShowImg("右图像");
	disp.ShowMatch(&showmatch, left.width, left.height); 
	disp.ShowDisp(&showdisp, left.width, left.height);


	cvWaitKey();	
}

void CDisparity200712Dlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
		int i = 0;
		  capture = 0;
  isHandOpen = 1;
	char filename[80];
	storage = cvCreateMemStorage(0);
	
 int numImg = 10;

char *names[] = { "./images/test01.jpg", "./images/test02.jpg", "./images/test03.jpg", "./images/test04.jpg", "./images/test05.jpg", 
"../images/test06.jpg", "./images/test07.jpg", "./images/test08.jpg", "./images/test09.jpg", "./images/test10.jpg"};
char *resultsiamge[] = {"result01.jpg","result02.jpg","result03.jpg","result04.jpg","result05.jpg","result06.jpg","result07.jpg",
"result08.jpg","result09.jpg","result10.jpg"};


	cvNamedWindow( "Template1", 1 );
	cvNamedWindow( "Template2", 1 );
	cvNamedWindow( "Comp Results1", 1 );
	cvNamedWindow( "Comp Results2", 1 );
	cvNamedWindow( "Skin Detection", 1 );

	cvNamedWindow("source",1);
	cvMoveWindow("source",0,0);

	cvNamedWindow( "Results", 1 );
	cvMoveWindow("Results",400,300);
	
	openHandTmpl = cvLoadImage("F:\\images\\openHandTmpl.jpg",1);
	if(!openHandTmpl)
		goto exitproc;
//	printf("open hand template image\n");
//	cvShowImage("source",openHandTmpl);
//			cvWaitKey(0);
	closedHandTmpl = cvLoadImage("F:\\images\\closedHandTmpl.jpg",1); 
//	printf("closed hand template image\n");		
//	cvShowImage("source",closedHandTmpl);
//			cvWaitKey(0);
	
	// Convert form RGB to GRAY
	tmplSize.width = openHandTmpl->width;
	tmplSize.height = openHandTmpl->height;
	
	openGrayHandTmpl = cvCreateImage( tmplSize, IPL_DEPTH_8U, 1);
	cvCvtColor( openHandTmpl, openGrayHandTmpl, CV_BGR2GRAY );
	
	tmplSize.width = closedHandTmpl->width;
	tmplSize.height = closedHandTmpl->height;
	
	closedGrayHandTmpl = cvCreateImage( tmplSize, IPL_DEPTH_8U, 1);
	cvCvtColor( closedHandTmpl, closedGrayHandTmpl, CV_BGR2GRAY );
	cvAddSearchPath("\\images\\");

	// Open the Output File
	output = fopen( "results.log", "w" );

	// Color for contour drawing
	color = CV_RGB( 255,255,255 );
	
	
	capture = cvCaptureFromCAM(0);


	
	if(capture != 0)
	{
		for(;;)
		{
			IplImage *frame;//, *frame_copy;
			if( !cvGrabFrame( capture ))
				break;
			frame = cvRetrieveFrame( capture );
			if( !frame )
				break;
			imgSize.width = frame->width;
			imgSize.height = frame->height;
            cvShowImage("source",frame);// added by liuzhi
//         frame_copy = cvCloneImage( frame );
		//	handDetect( frame );
			if( cvWaitKey( 10 ) >= 0 )
				break;
		}
		
		cvReleaseCapture( &capture );
	}
	else
	{
		
		for ( i = 0; i < numImg; i++ )
		{
			fprintf(output, "Image %i %s ************************\n", i+1, names);
			strcpy(filename, "result_");
//			cvNamedWindow( names[i], 1 ); 
//			cvNamedWindow("source",1);
//			cvMoveWindow("source",0,0);
			img = cvLoadImage(names[i],1);     
//			printf("source image\n");
//			cvShowImage("source",img);
//			cvWaitKey(0);
			if( img )
			{
				imgSize.width = img->width;
				imgSize.height = img->height;
				
				handDetect( img );
//				strcat(filename, names[i]);
				cvSaveImage(resultsiamge[i], img);
				cvReleaseImage(&img);
			}
		}
		cvWaitKey(0);
		
//		for ( i = 0; i < numImg; i++ )
//		{
//			cvDestroyWindow( names[i]);         
//		}
	}
exitproc:	cvReleaseImage(&tmpImg);
	
	cvReleaseImage(&conv);
	cvReleaseImage(&H);
	cvReleaseImage(&S);
	cvReleaseImage(&V);
	cvReleaseImage(&tmpH1);
	cvReleaseImage(&tmpH2);
	cvReleaseImage(&tmpH3);
	cvReleaseImage(&tmpS1);
	cvReleaseImage(&tmpS2);
	cvReleaseImage(&tmpS3);
	cvReleaseImage(&openHandTmpl);
	cvReleaseImage(&closedHandTmpl);
	cvReleaseImage(&openGrayHandTmpl);
	cvReleaseImage(&closedGrayHandTmpl);
	cvReleaseImage(&openscaledTmpl);
	cvReleaseImage(&closedscaledTmpl);
	cvReleaseImage(&openMatchResult);
	cvReleaseImage(&closedMatchResult);
	cvReleaseMemStorage(&storage);
	if(output)
		fclose( output );
//	cvDestroyWindow( "Result");     
	

	cvDestroyWindow( "Template1");
	cvDestroyWindow( "Template2" );
	cvDestroyWindow( "Comp Results1" );
	cvDestroyWindow( "Comp Results2" );
	cvDestroyWindow( "Skin Detection" );

	
	
	
}


void CDisparity200712Dlg::handDetect( IplImage *img)
{
//  CvSize tmplSize;
	CvSize resultSize;
	IplConvKernel *erosionElement, *dilationElement;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -