#include <windows.h>
#include "vfw.h"
#pragma comment(lib, "vfw32.lib")
#define BITMAP_MAXSIZE (1024*768*3+10)
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK FramInfo(HWND, LPVIDEOHDR);
HINSTANCE g_hInst;
HWND HWndMain;
LPCTSTR lpszClass=TEXT("WiseCat");
HWND vfw;
BITMAPINFO Bm;
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst = hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow( lpszClass
,lpszClass
,WS_OVERLAPPEDWINDOW
,CW_USEDEFAULT
,CW_USEDEFAULT
,CW_USEDEFAULT,CW_USEDEFAULT
,NULL
,(HMENU)NULL
,hInstance
,NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,NULL,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
HDC hdc;
///////////////////////////////////////////////////
HDC MemDC, Hdc;
PAINTSTRUCT ps;
HANDLE hFile;
static unsigned char * BMbuf;
static BITMAPFILEHEADER * stpBFH;
static BITMAPINFOHEADER * stpBIH;
//static unsigned int uiX;
//static unsigned int uiPad;
static unsigned char * ucpPixel;
static DWORD dwRead;
HBITMAP OldBitmap;
///////////////////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
switch(iMessage)
{
case WM_CREATE:
/////////////////////////////////////BITMAP 적재////////////////////////////////////////////////////
hFile = CreateFile(TEXT("image.bmp"),
GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
MessageBox(hWnd,TEXT("smart.bmp 를 찾을수 없습니다"),TEXT("ㅋㅋ실패ㅋㅋㅋ"),MB_OK);
DestroyWindow(hWnd);
}
BMbuf = (unsigned char *)malloc(BITMAP_MAXSIZE);
if(BMbuf == 0)
{
MessageBox(hWnd,TEXT("동적할당 생성 실패"),TEXT("ㅋㅋ실패ㅋㅋㅋ"),MB_OK);
DestroyWindow(hWnd);
}
ReadFile(hFile,BMbuf,BITMAP_MAXSIZE,&dwRead,NULL);
stpBFH = (BITMAPFILEHEADER *)BMbuf;
stpBIH = ((BITMAPINFOHEADER *)((char *)BMbuf + sizeof(BITMAPFILEHEADER)) );
CloseHandle(hFile);
// uiPad = uiX%4;
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HWndMain = hWnd;
vfw = capCreateCaptureWindow( TEXT("CAM")
,WS_CHILD | WS_VISIBLE
,0
,0
,400
,300
,hWnd
,NULL);
capDriverConnect(vfw,0);
capGetVideoFormat(vfw,&Bm,sizeof(Bm));
Bm.bmiHeader.biWidth = 320;
Bm.bmiHeader.biHeight = 240;
capSetVideoFormat(vfw,&Bm,sizeof(Bm));
//capDlgVideoFormat(m_capwnd);
capSetCallbackOnFrame(vfw, FramInfo);
capPreviewRate(vfw, 1);
capPreview(vfw, FALSE);
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
LRESULT CALLBACK FramInfo(HWND hWnd, LPVIDEOHDR lpData)
{
static int iCntX;
static int iCntY;
static int Jump;
hdc = GetDC(HWndMain);
StretchDIBits(hdc , 0
, 0
, Bm.bmiHeader.biWidth
, Bm.bmiHeader.biHeight
, 0
, 0
, Bm.bmiHeader.biWidth
, Bm.bmiHeader.biHeight
, lpData->lpData
, &Bm
, DIB_RGB_COLORS
, SRCCOPY);
Jump= 0;
ucpPixel = BMbuf + stpBFH->bfOffBits;
for(iCntY = 0; iCntY < Bm.bmiHeader.biHeight ; ++iCntY)
{
for(iCntX = 0; iCntX < Bm.bmiHeader.biWidth ; ++iCntX, Jump += 3, ucpPixel = ucpPixel+3)
{
if(lpData->lpData[Jump + 2] > 100)
{
continue;
}
if(lpData->lpData[Jump + 1] > 100)
{
continue;
}
if(lpData->lpData[Jump + 0] > 50)
{
//lpData->lpData[Jump] = 0; // Blue
//lpData->lpData[Jump + 2] = 255; // Red
//lpData->lpData[Jump + 1] = 0; // Green
lpData->lpData[Jump + 2] = *(ucpPixel+2);
lpData->lpData[Jump + 1] = *(ucpPixel+1);
lpData->lpData[Jump + 0] = *(ucpPixel+0);
}
}
//ucpPixel = ucpPixel + uiPad;
}
/*
for(iCntY = 0; iCntY < Bm.bmiHeader.biHeight ; ++iCntY)
{
for(iCntX = 0; iCntX < Bm.bmiHeader.biWidth ; ++iCntX, Jump += 3 )
{
if(lpData->lpData[Jump + 2] > 100)
{
continue;
}
if(lpData->lpData[Jump + 1] > 100)
{
continue;
}
if(lpData->lpData[Jump + 0] > 50)
{
lpData->lpData[Jump] = 0; // Blue
lpData->lpData[Jump + 2] = 255; // Red
lpData->lpData[Jump + 1] = 0; // Green
}
}
}*/
StretchDIBits(hdc , Bm.bmiHeader.biWidth +20
, 0
, Bm.bmiHeader.biWidth
, Bm.bmiHeader.biHeight
, 0
, 0
, Bm.bmiHeader.biWidth
, Bm.bmiHeader.biHeight
, lpData->lpData
, &Bm
, DIB_RGB_COLORS
, SRCCOPY);
ReleaseDC(HWndMain, hdc);
return 0;
}
결과 :
'코스웨어 > 14년 스마트컨트롤러' 카테고리의 다른 글
20141007 영상처리 허수웅 (0) | 2014.10.08 |
---|---|
2014.10.07. 업무일지 [출석번호 22 허수웅] (5) | 2014.10.08 |
20141007 영상처리 - 손병규 (0) | 2014.10.07 |
영상처리 - 이경진 (0) | 2014.10.07 |
2014.10.02 업무일지 [출석번호 21 이재우] (8) | 2014.10.07 |
10. 02 업무일지 [ 이경진 ] (13) | 2014.10.06 |
2014.10.01 업무일지 18번 오영주 (5) | 2014.10.02 |
2014.09.30 일일 교육보고 - 오두환 (11) | 2014.09.30 |