资源简介
图像处理代码 差影法
图象的检测,模板匹配
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
评论
共有 条评论