프로젝트/주차관리시스템

PVS :: [VFW] 카메라 캡쳐 후 JPEG 파일로 만들기 2

appHunter 2009. 5. 7. 10:20
글을 다 날려서 다시 적는다. !!  (2009-05-06에 날림)
2007/06/21 17:33  원본보기


해당 위치에 있는 자동차를 캡쳐해서 JPEG 파일 생성한다.


참고 링크 : http://blog.naver.com/crazrain/130005867805

참고링크의 냐옹님의 강좌를 참고하여 만들었다.


1. 생성자, 소멸자
// 생성자 만듬.  VideoCaputre.h
CVideoCapture(CWnd * pParnetWnd,LPSTR name);

// VideoCapture.cpp
CVideoCapture::CVideoCapture(CWnd * pParnetWnd,LPSTR name)
{
    // 1 . 생성자 소멸자를 만듬.
    m_parentWnd = pParnetWnd->m_hWnd;
    fileName = name;                                  // jpeg 파일명
}
CVideoCapture::~CVideoCapture()
{
    ::DestroyWindow(m_capWnd);
    m_capWnd = NULL;
}

2. VFW 라이브러리를 불러오기

// 2. VFW 라이브러리 가져오기  ( VideoCapture.h )
#include <vfw.h>
#pragma comment (lib,"vfw32.lib")


3. 캡쳐 화면을 표시할 윈도우를 생성

// 3. 캡쳐 윈도우 생성 ( initCamera() 메서드 )
m_capWnd = capCreateCaptureWindow("Capture",WS_CHILD | WS_VISIBLE , 0, 0 ,
                                        320,240 , m_parentWnd,NULL );
if ( NULL == m_capWnd) {
        AfxMessageBox("윈도우 생성 실패");
        return FALSE;
}

4. 장치 연결 수 체크 메서드


int CVideoCapture::enumCapDrivers()
{
    int numDrivers = 0;
    char Device[128], Version[128];
    int index;
    for(index=0 ; index < 9 ; index ++) {
        if (TRUE == capGetDriverDescription(index,Device,128,Version,128)){           
            numDrivers++;
            //AfxMessageBox(Device);        //디바이스 명 보여주기.
        }
    }     
    return numDrivers;
}
// 4.  장치 연결수 체크 ( initCamera() 메서드 )
int numDrivers = 0;
numDrivers = enumCapDrivers();
if(numDrivers == 0) {
      AfxMessageBox("장치 드라이버가 하나도 없어요");
      return FALSE;
}

5. 장치에 연결


// 5. 장치 연결  ( initCamera() 메서드 )
if ( ! capDriverConnect(m_capWnd,0)) {
     AfxMessageBox("캡쳐 장치 연결 실패");
     return FALSE;
}

return TRUE;

6. 캡쳐 시작

// 6. 캡쳐 시작  ( captureStart() 메서드 )
capGrabFrameNoStop(m_capWnd);
capFileSaveDIB(m_capWnd, fileName); //캡쳐하기 ( 화면 내용을 bmp 으로 )
return TRUE;

7. 장치 분리

// 7. 캡쳐 정지 및 분리 ( captureStop() 메서드 )

capCaptureStop(m_capWnd);
capCaptureAbort(m_capWnd);   
capDriverDisconnect(m_capWnd);
return TRUE;

8. 헤더 파일 추가

// 8. 헤더 추가 ( TheOneDlg.h )
#include "VideoCapture.h"



9. 클래스 변수를 선언

// 9. 클래스 변수 선언 ( TheOneDlg.h )
CVideoCapture * p_vidcap;

10. 시작하자마자 캡쳐 종료하기 위해 OnInitDialog() 메서드에서 수행

//10 수행. ( CTheOneDlg.cpp 파일 OnInitDialog() 메서드 )
//.... 제일 밑에 추가
p_vidcap = new CVideoCapture(this,__argv[1]);
p_vidcap->initCamera();
p_vidcap->captureStart();
p_vidcap->captureStop();  

OnCancel();  // 캡쳐하자마자 종료하게 하기 위해..



기타 

캡쳐되고 있는 화면을 보고 싶으면

captureStart() 메서드에
    capPreviewRate(m_capWnd,TRUE);    capPreview(m_capWnd,TRUE);   
을 추가 한

OnInitDialog() 메서드에서
    //p_vidcap->captureStop(); 
    //OnCancel(); 

을 주석처리 하면 된다.


사용자 삽입 이미지


이전으로 : PVS :: [VFW] 카메라 캡쳐 JPEG 파일 만들기 1
다음으로 : PVS :: [VFW] 카메라 캡쳐 JPEG 파일 만들기 3