資源簡介
圖像處理代碼 差影法
圖象的檢測,模板匹配
source目錄下為本章介紹的源程序
功能是圖象的檢測,模板匹配
命令行編譯過程如下
vcvars32
rc bmp.rc
cl detect.c bmp.res user32.lib gdi32.lib
注意事項:
運行時,文件c:\test.bmp必須存在

代碼片段和文件信息
//////////////////////////////////////////////////////////////
//Name:detect.c
//Purpose:?Image?detection
//Author:?phoenix?CS?TshingHua?Beijing?P.R.C.
//Email:?bjlufengjun@www.163.net?or?lufengjun@hotmail.com
//Date:April?3?1998
//header?file
#include?“bmp.h“
#include?“memory.h“
#include?“math.h“
#include?“stdio.h“
//owner?defined?stack
typedef?struct{
??HGLOBAL?hMem;
?? ??POINT?*lpMyStack;
??LONG??ElementsNum;
??LONG??ptr;
??}MYSTACK;
//macro?definition
#define?WIDTHBYTES(i)????((i+31)/32*4)
//function?declaration
int?PASCAL?WinMain?(HANDLE?HANDLE?LPSTR?int);
LRESULT?CALLBACK?MainWndProc(HWND??UINTWPARAM?LPARAM);
BOOL?LoadBmpFile?(HWND?hWndchar?*BmpFileName);
BOOL?Projection(HWND?hWndBOOL?Hori);
BOOL?Subtraction(HWND?hWnd);
//global?variable?declaration
BITMAPFILEHEADER???bf;
BITMAPINFOHEADER???bi;
HPALETTE???????????hPalette=NULL;
HBITMAP????????????hBitmap=NULL;
HGLOBAL????????????hImgData=NULL;
DWORD??????????????NumColors;
DWORD??????????????LineBytes;
DWORD??????????????ImgWidth=0??ImgHeight=0;
///////////////////////////////////////////////////////////
int?PASCAL?WinMain?(HANDLE?hInstance?HANDLE?hPrevInstance
????LPSTR?lpszCmdLine?int?nCmdShow)
{
MSG???????msg;
WNDCLASS??wndclass;
HWND??????hWnd;
if?(?!?hPrevInstance?){
wndclass.style?=?CS_HREDRAW?|?CS_VREDRAW;
wndclass.lpfnWndProc?=?MainWndProc;
wndclass.cbClsExtra?=?0;
wndclass.cbWndExtra?=?0;
wndclass.hInstance?=?hInstance;
wndclass.hIcon?=?LoadIcon?(NULL?IDI_APPLICATION);
wndclass.hCursor?=?LoadCursor?(NULL?IDC_ARROW);
wndclass.hbrBackground?=?GetStockobject?(WHITE_BRUSH);
wndclass.lpszMenuName?=??“BMPMENU“;
wndclass.lpszClassName?=?“phoenix?ip?system“;
????}
????if?(?!?RegisterClass?(&wndclass)?)
return?FALSE;
?
hWnd?=?CreateWindow?(“phoenix?ip?system““Image?detection“
?WS_OVERLAPPEDWINDOWCW_USEDEFAULTCW_USEDEFAULT
?CW_USEDEFAULT CW_USEDEFAULT?NULLNULL
?hInstance NULL);
if?(!hWnd)
return?FALSE;
ShowWindow?(hWnd?SW_SHOWMAXIMIZED);
UpdateWindow?(hWnd);
while?(?GetMessage?(&msg?NULL?0?0)?){
TranslateMessage?(&msg);
DispatchMessage?(&msg);
????}
return?msg.wParam;
}
////////////////////////////////////////////////////////////////
LRESULT?CALLBACK?MainWndProc(HWND?hWnd?UINT?messageWPARAM?wParam?LPARAM?lParam)
{
????static??HDC????hDChMemDC;
????PAINTSTRUCT????ps;
????switch?(message){
????case?WM_PAINT:
{?????????
hDC?=?BeginPaint(hWnd?&ps);
if?(hBitmap)
{?
hMemDC?=?CreateCompatibleDC(hDC);
if?(hPalette)
{???????????
SelectPalette?(hDC?hPalette?FALSE);?
SelectPalette?(hMemDC?hPalette?FALSE);
RealizePalette?(hDC);
}???
Selectobject(hMemDC?hBitmap);?
BitBlt(hDC?0?0?ImgWidthImgHeight?hMemDC?0?0?SRCCOPY);
DeleteDC(hMemDC);
}
EndPaint(hWnd?&ps);
break;
}
case?WM_DESTROY:?//注意釋放內存和位圖,調色板句柄
????????if(hBitmap!=NULL)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????215??1999-01-02?20:01??readme.txt
?????文件?????????620??1998-04-22?15:20??Bmp.rc
?????文件???????13391??1998-04-22?20:19??detect.c
?????文件???????38400??1998-01-15?08:08??detect.exe
?????文件?????????263??1998-04-22?15:26??Bmp.h
評論
共有 條評論