본문 바로가기
기술자료/JPEG 압축 영상

과제 - 영상처리 - 다음을 고찰하라...

by 와이즈캣 2009. 8. 7.
728x90
반응형
#include <windows.h>
#include "vfw.h"
#pragma comment(lib, "vfw32.lib")

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;

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
  PAINTSTRUCT ps;

  switch(iMessage)
  {
    case WM_CREATE:
      HWndMain = hWnd;
      vfw = capCreateCaptureWindow(  TEXT("CAM")
                      ,WS_CHILD | WS_VISIBLE
                      ,0
                      ,0
                      ,400
                      ,300
                      ,hWnd
                      ,NULL);

      capDriverConnect(vfw,0);
      capGetVideoFormat(vfw,&Bm,sizeof(Bm));
      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;
  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;
}
728x90