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

📄 testdlg.cpp

📁 一个基于灰度值的视频检索程序,主要是计算灰度值,对图像进行检索.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// testDlg.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "testDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog

CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
			flag=0;
	imge_count=0;
	long i,j;
	for(i=0;i<450;i++)
	for(j=0;j<256;j++)
	{
	  //m_lCount1[i][j]=0;
	  //m_lCount2[i][j]=0;
	  m_lCount3[i][j]=0;
	}

	GetCurrentDirectory(256,m_path);	
	str_Temp.Format("%s",m_path);	
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDlg)
	DDX_Control(pDX, IDC_LIST1, m_ListFound);
	DDX_Control(pDX, IDC_PROGRESS1, m_progress);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnOpenimage)
	ON_BN_CLICKED(IDC_ABSTRACT, OnAbstract)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE1, OnStaticSearchimage1)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE2, OnStaticSearchimage2)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE10, OnStaticSearchimage10)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE3, OnStaticSearchimage3)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE4, OnStaticSearchimage4)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE5, OnStaticSearchimage5)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE6, OnStaticSearchimage6)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE7, OnStaticSearchimage7)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE8, OnStaticSearchimage8)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGE9, OnStaticSearchimage9)
	ON_WM_TIMER()
	ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
	ON_BN_CLICKED(IDC_STATIC_KEYIMAGE, OnStaticKeyimage)
	ON_BN_CLICKED(IDC_STATIC_SEARCHIMAGEALL, OnStaticSearchimageall)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers

BOOL CTestDlg::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 CTestDlg::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 CTestDlg::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
	{
		RefreshDisplay();
		CDialog::OnPaint();
	}
}

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

void CTestDlg::RefreshDisplay()
{

		if( m_imgLoaded.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_KEYIMAGE);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgLoaded.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}

	if( m_imgSearch1.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE1);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch1.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}
		if( m_imgSearch2.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE2);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch2.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}

			if( m_imgSearch3.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE3);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch3.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}


	if( m_imgSearch4.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE4);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch4.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}


		if( m_imgSearch5.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE5);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch5.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}

			if( m_imgSearch6.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE6);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch6.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}
				if( m_imgSearch7.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE7);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch7.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}

					if( m_imgSearch8.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE8);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch8.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}

	if( m_imgSearch9.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE9);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch9.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}


		if( m_imgSearch10.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGE10);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearch10.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}

		//m_imgSearchall
			if( m_imgSearchall.IsValid() )
	{
		CRect r;			
		CWnd *p = (CWnd*) GetDlgItem(IDC_STATIC_SEARCHIMAGEALL);
		CDC *pDC = p->GetDC();
		p->GetWindowRect(&r);
		
		
		m_imgSearchall.Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());
		p->ReleaseDC(pDC);
	}


}

void CTestDlg::OnOpenimage() 
{
	// TODO: Add your control notification handler code here
		char szFilter[] = "Bmp File (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0\0";//文件滤波器
	CFileDialog dlg(TRUE);
	CString strTemp;
	CString strTemp1;
//	CString strNamaFile;
	ULONG ulJumlahRecords;
	int iLoopRecNo = 0;
	//
	CxImage imgTemp;
	CxImage rfft1;
	CxImage ifft1;
	int iWidth = 256;
	int iHeight = 256;
	
	int iPixelSize = 1; // 1=GrayScale, 3=24bpp, 4=32bpp
	int iBlockSize = 16;
	int i = iWidth/iBlockSize;
	int j = iHeight/iBlockSize;
	
	int iRow;
	int iCol;
	int iLoopRow;
	int iLoopCol;
	double dTemp;
	int iBlockNum = 0;
	long lVal1;
	BYTE *pImage;
	
	//
	//
	//
	ulJumlahRecords = 0L;
	//dlg.m_ofn.lpstrInitialDir = m_strLokasiLogFile;
	dlg.m_ofn.lpstrFilter = szFilter;

	if( dlg.DoModal() == IDOK )
	{
		strNamaFile = dlg.GetPathName();
		m_imgLoaded.Load(strNamaFile, CXIMAGE_FORMAT_BMP);
		RefreshDisplay();

		if( !m_imgLoaded.IsValid() ) return;
		
		//
		imgTemp.Copy(m_imgLoaded);
		imgTemp.Resample(iWidth, iHeight);
		imgTemp.FFT2(&imgTemp, &imgTemp, &rfft1, &ifft1);		
		pImage = rfft1.GetBits();

		//
		for(iRow = 0; iRow < iHeight; iRow += iBlockSize)
		{		
			for(iCol = 0; iCol < iWidth; iCol += iBlockSize )
			{
				// Block Processing
				m_KeySignature[iBlockNum] = 0.0;
				dTemp = 0.0;
				for(iLoopRow = 0; iLoopRow < iBlockSize; iLoopRow++ )
				{
					for(iLoopCol = 0; iLoopCol < iBlockSize; iLoopCol++ )
					{
						lVal1 = pImage[((iRow+iLoopRow)*iPixelSize*iWidth) + ((iCol+iLoopCol)*iPixelSize)];
						dTemp += (double) lVal1;
					}
				}
				
				m_KeySignature[iBlockNum] = sqrt(dTemp);
				iBlockNum++;
			}
		}
		
		//
		// Normalize
		//
		dTemp = 0;
		for(i = 0; i < 256; i++ )
		{
			dTemp += m_KeySignature[i];
		}
		
		for(i = 0; i < 256; i++ )
		{
			m_KeySignature[i] /= dTemp;
		}
		
	}
	else
	{
		AfxMessageBox("Please select a BMP file!");
		return;
	}	


}


void CTestDlg::OnAbstract() 
{
	// TODO: Add your control notification handler code here
	   m_time1=GetCurrentTime();
	   int ntime1_m=m_time1.GetMinute();
       int ntime1_s=m_time1.GetSecond();

	m_progress.SetRange(0,50);   
          m_progress.SetPos(0);   
           
	CString pathstr;
pathstr=str_Temp+"\\image\\";
//nt j=0;
//athstr.Format(str_Temp+"\\image\\%d.bmp",j);

   	counts=0;

       CString tempath;

       CString temps;

       tempath=pathstr;

       tempath.TrimRight();tempath.TrimLeft(); //去除前后多余

       CString strfilepath=tempath;

    
       StartDir(strfilepath);

  

    //AfxMessageBox(counts);
	
	//	 CBmpProc *pDestBmp;
	CString comp_pic_path;
//	CBmpProc bmp;    
//	CWnd *pWnd;
 //  	CRect rect;
	
	for(int comp_pic=0;comp_pic<counts;comp_pic++)
  {
	
	

	comp_pic_path.Format(str_Temp+"\\image\\%d.bmp",comp_pic);

	Dflag=docufile.OnOpenDocument(comp_pic_path);
	
   //指向DIB的指针
	LPSTR lpDIB;
	//指向DIB像素指针
	LPSTR lpDIBBits;
    //获取DIB
	HDIB hDIB =docufile.m_hDIB ;
	//锁定DIB
	lpDIB=(LPSTR)::GlobalLock((HGLOBAL)hDIB);
    //找到DIB图像像素起始位置
	lpDIBBits=::FindDIBBits(lpDIB);
    
	//图像每行的字节数
	long lLineBytes;
	
	//计算图像的宽度和高度
    long m_lWidth=::DIBWidth(lpDIB);
	long m_lHeight=::DIBHeight(lpDIB);
	//计算图像每行的字节数
	lLineBytes=WIDTHBYTES(m_lWidth*8);
	
    //循环变量
	long i;
	long j;
  
    unsigned char *lpSrc1;
	//计算各个灰度值的计数
	for(i=0;i<m_lHeight;i++)
	for(j=0;j<m_lWidth;j++)
		{
		lpSrc1 = (unsigned char*)lpDIBBits + lLineBytes * i*3 + j*3;

⌨️ 快捷键说明

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