예제 #1
0
//open sequence grabber component instance and draw to window
CWinVideoGrabber::CWinVideoGrabber(HWND whichwindow)
{ 
	parentwindow = whichwindow;
	videomode = VIDEOGRABBERMODE_NONE;
	videowindow = capCreateCaptureWindow("CAPTURE", WS_CHILD | WS_VISIBLE, 0, 0, 160, 120, (HWND) whichwindow, winid++); 
	SendMessage (videowindow, WM_CAP_DRIVER_CONNECT, 0, 0L); 
	capPreviewScale(videowindow,True);
	capPreviewRate(videowindow, 50);
	Init();
}
// Standard AVIcap window message 
// macro: capPreviewRate
BOOL	CAviCap::SetPreviewRate(int Rate)
{
	CHECKWIN();
	CHECKCNCT();
	if(Rate<0)	return FALSE;
	if(capPreviewRate(GetSafeHwnd(), Rate))
		{_previewRate=Rate; return TRUE;}

	return FALSE;
}
예제 #3
0
// Initialize camera input
bool CvCaptureCAM_VFW::open( int wIndex )
{
    char szDeviceName[80];
    char szDeviceVersion[80];
    HWND hWndC = 0;

    close();

    if( (unsigned)wIndex >= 10 )
        wIndex = 0;

    for( ; wIndex < 10; wIndex++ )
    {
        if( capGetDriverDescription( wIndex, szDeviceName,
            sizeof (szDeviceName), szDeviceVersion,
            sizeof (szDeviceVersion)))
        {
            hWndC = capCreateCaptureWindow ( "My Own Capture Window",
                WS_POPUP | WS_CHILD, 0, 0, 320, 240, 0, 0);
            if( capDriverConnect (hWndC, wIndex))
                break;
            DestroyWindow( hWndC );
            hWndC = 0;
        }
    }

    if( hWndC )
    {
        capWnd = hWndC;
        hdr = 0;
        hic = 0;
        fourcc = (DWORD)-1;

        memset( &caps, 0, sizeof(caps));
        capDriverGetCaps( hWndC, &caps, sizeof(&caps));
        ::MoveWindow( hWndC, 0, 0, 320, 240, TRUE );
        capSetUserData( hWndC, (size_t)this );
        capSetCallbackOnFrame( hWndC, frameCallback );
        CAPTUREPARMS p;
        capCaptureGetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
        p.dwRequestMicroSecPerFrame = 66667/2;
        capCaptureSetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
        //capPreview( hWndC, 1 );
        capPreviewScale(hWndC,FALSE);
        capPreviewRate(hWndC,1);
    }
    return capWnd != 0;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//카메라 초기화.
bool CWebCam::StartCam(CWnd* wnd, int nWidth, int nHeight, BITMAPINFO& bmpInfo) //wnd :캡처하는 영상이 나타날, 윈도우의 포인터를 넘겨받는다. 
                                                                                // bmpInfo : 영상의 규격을 얻는것 , 크래스 외부에서 작업을 수행할 수 있다.
{
	// 캡쳐 영상을 출력할 윈도우의 크기 및 위치 조절
	m_hCam = capCreateCaptureWindow("Cam Capture", WS_CHILD | WS_VISIBLE,
		0, 0, nWidth, nHeight, wnd->m_hWnd, NULL);   // 유니코드 지원 여부에 따라 각각 함수 실행. 촬영하는 영상의 규격과는 상관이 없다. 

	if (!capDriverConnect(m_hCam, 0))                //캡처 윈도우를 카메라와 연결한다. 
	{
		AfxMessageBox("연결된 카메라를 찾을 수 없습니다.");
		return false;
	}

	//	capDlgVideoFormat(m_hCam);
	capGetVideoFormat(m_hCam, &bmpInfo, sizeof(BITMAPINFO));     //캡처영상을 사용하려면 영상의 규격정보를 알아야한다. 

	// 캡쳐 영상의 크기를 희망 값으로 설정
	bmpInfo.bmiHeader.biWidth = nWidth;
	bmpInfo.bmiHeader.biHeight = nHeight;
	bmpInfo.bmiHeader.biSizeImage = nWidth*nHeight*bmpInfo.bmiHeader.biBitCount / 8;

	if (!capSetVideoFormat(m_hCam, &bmpInfo, sizeof(BITMAPINFO)))  //카메라의 영상 규격(크기와 색 형식 정보등)을 설정한다. 
	{
		// 설정에 실패하면 원래 값으로 되돌림
		capGetVideoFormat(m_hCam, &bmpInfo, sizeof(BITMAPINFO));
	}

	// 캡쳐 영상이 24비트 RGB가 될 수 있도록 설정
	bmpInfo.bmiHeader.biBitCount = 24;
	bmpInfo.bmiHeader.biCompression = BI_RGB;
	if (!capSetVideoFormat(m_hCam, &bmpInfo, sizeof(BITMAPINFO)))
	{
		// 설정에 실패하면 원래 값으로 되돌림
		capGetVideoFormat(m_hCam, &bmpInfo, sizeof(BITMAPINFO));
	}

	capOverlay(m_hCam, TRUE); //그래픽 하드웨어를 이용할 것인지 결정.   *오버레이를 활성화하면 미리보기가 자동으로 비활성화됨.
	capPreviewRate(m_hCam,30); //미리보기를 갱신하는 시간 간격을 설정.
	capPreview(m_hCam, TRUE);   //미리보기를 활성화 할 것인지 결정.

	return true;
}
예제 #5
0
파일: mmcamera.c 프로젝트: sfsy1989/j2me
/**
 * Set camera preview window
 */
static HWND camera_set_preview_window(javacall_handle handle, 

                                      int x, int y, int w, int h, BOOL visible)
{
#define DEFAULT_CAPTURE_DRIVER  0   
#define DEFAULT_PREVIEW_RATE    150 
    /* ms unit => Increase this value to optimize performance */
    
    BOOL ret;
    camera_handle* pHandle = (camera_handle*)handle;
    DWORD wsVisible = TRUE == visible ? WS_VISIBLE : 0;

    camera_destroy_window(pHandle);

    JAVA_DEBUG_PRINT4("[camera] capCreateCaptureWindow %d %d %d %d\n", x, y, w, h);

    pHandle->hCapWnd = capCreateCaptureWindow(_T("Sun_Java_Cap_Window"), 
                   wsVisible | WS_CHILD | WS_CLIPSIBLINGS, 
                   x + X_SCREEN_OFFSET, y + Y_SCREEN_OFFSET + TOP_BAR_HEIGHT, 
                   w, h, GET_MCIWND_HWND(), 0xffff);

    JAVA_DEBUG_PRINT1("[camera] capCreateCaptureWindow %d\n", pHandle->hCapWnd);

    if (pHandle->hCapWnd) {
        ret = capDriverConnect(pHandle->hCapWnd, DEFAULT_CAPTURE_DRIVER);
        if (FALSE == ret) {
            JAVA_DEBUG_PRINT(
                "[camera] capDriverConnect fail - is there camera attached?\n");
            DestroyWindow(pHandle->hCapWnd);
            pHandle->hCapWnd = NULL;
            return NULL;
        }
        capSetCallbackOnFrame(pHandle->hCapWnd, camera_grabber_callback);
        capPreviewScale(pHandle->hCapWnd, TRUE);
        capPreviewRate(pHandle->hCapWnd, DEFAULT_PREVIEW_RATE);
    }

    return pHandle->hCapWnd;
}
예제 #6
0
//Description: sets up an imaging device for capture operations
//Input: digitizer ID number and a dummy string
//Output: returns success (non-negative) or failure
EXPORT long SetUp(long driver, long width, long height){

	//reset the image and size variables
	pImage = NULL;
	dwSize = 0;

	//make sure we don't already have a window
	if(hWndC == NULL) {
		//create the capture window, the window is currently being draw in the top left corner
		//because the buffer is filled with nothing if it is not being drawn on the screen;
		//only a window size of 1x1 is needed to get this to work
		hWndC = capCreateCaptureWindow(TEXT("Webcam Capture Window"), WS_CHILD | WS_VISIBLE, 0, 0,
			1, 1, GetDesktopWindow(), 0); 
	}

	//connect the selected driver to the window
	if(!capDriverConnect(hWndC, driver)) {
		DestroyWindow(hWndC);
		return -1;
	}

	//create a frame capture callback function
	if(!capSetCallbackOnFrame(hWndC, capFrame)) {
		capDriverDisconnect(hWndC);
		DestroyWindow(hWndC);
		return -1;
	}


	//begin previewing
	capPreviewRate(hWndC, 66);
	if(!capPreview(hWndC, TRUE)) {
		capDriverDisconnect(hWndC);
		DestroyWindow(hWndC);
		return -1;
	}

	return 0;
}
예제 #7
0
/*初始化VFW设备*/ 
void CMainFrame::OnVfwInitvfw()
{
	// TODO: 在此添加命令处理程序代码
	DWORD fsize;

	// 创建视频窗口
	if(!m_wndSource.CreateEx(WS_EX_TOPMOST,NULL,
							_T("Source"),WS_OVERLAPPED|WS_CAPTION,
							CRect(0,0,352,288),NULL,0))
		return;
	
	m_hWndCap = capCreateCaptureWindow(_T("Capture Window"),WS_CHILD|WS_VISIBLE,
									  0,0,352,288,
									  m_wndSource.m_hWnd,0);

	//m_wndSource.ShowWindow(SW_SHOW);
	// 注册回调函数
	capSetCallbackOnError(m_hWndCap,(FARPROC)ErrorCallbackProc);
	capSetCallbackOnStatus(m_hWndCap,(FARPROC)StatusCallbackProc);
	capSetCallbackOnVideoStream(m_hWndCap,(FARPROC)VideoCallbackProc);

	// 连接视频设备
	capDriverConnect(m_hWndCap,0);	//(HWND m_hWndCap, int index);//index : 0--9
	// 获取驱动器的性能参数
	capDriverGetCaps(m_hWndCap,&m_caps,sizeof(CAPDRIVERCAPS));
	if (m_caps.fHasOverlay)
		capOverlay(m_hWndCap,TRUE);
	// 设置预览速率开始预览
	capPreviewRate(m_hWndCap,1000/25);
	capPreview(m_hWndCap,bPreview);


	fsize = capGetVideoFormatSize(m_hWndCap);
	capGetVideoFormat(m_hWndCap, lpbiIn, fsize);
	
	AfxMessageBox(_T("初始化成功!"));
}
예제 #8
0
파일: cap_vfw.cpp 프로젝트: 12rohanb/opencv
// Initialize camera input
bool CvCaptureCAM_VFW::open( int wIndex )
{
    char szDeviceName[80];
    char szDeviceVersion[80];
    HWND hWndC = 0;

    close();

    if( (unsigned)wIndex >= 10 )
        wIndex = 0;

    for( ; wIndex < 10; wIndex++ )
    {
        if( capGetDriverDescription( wIndex, szDeviceName,
            sizeof (szDeviceName), szDeviceVersion,
            sizeof (szDeviceVersion)))
        {
            hWndC = capCreateCaptureWindow ( "My Own Capture Window",
                WS_POPUP | WS_CHILD, 0, 0, 320, 240, 0, 0);
            if( capDriverConnect (hWndC, wIndex))
                break;
            DestroyWindow( hWndC );
            hWndC = 0;
        }
    }

    if( hWndC )
    {
        capWnd = hWndC;
        hdr = 0;
        hic = 0;
        fourcc = (DWORD)-1;

        memset( &caps, 0, sizeof(caps));
        capDriverGetCaps( hWndC, &caps, sizeof(caps));
        CAPSTATUS status = {};
        capGetStatus(hWndC, &status, sizeof(status));
        ::SetWindowPos(hWndC, NULL, 0, 0, status.uiImageWidth, status.uiImageHeight, SWP_NOZORDER|SWP_NOMOVE);
        capSetUserData( hWndC, (size_t)this );
        capSetCallbackOnFrame( hWndC, frameCallback );
        CAPTUREPARMS p;
        capCaptureGetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
        p.dwRequestMicroSecPerFrame = 66667/2; // 30 FPS
        capCaptureSetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
        //capPreview( hWndC, 1 );
        capPreviewScale(hWndC,FALSE);
        capPreviewRate(hWndC,1);

        // Get frame initial parameters.
        const DWORD size = capGetVideoFormatSize(capWnd);
        if( size > 0 )
        {
            unsigned char *pbi = new unsigned char[size];
            if( pbi )
            {
                if( capGetVideoFormat(capWnd, pbi, size) == size )
                {
                    BITMAPINFOHEADER& vfmt = ((BITMAPINFO*)pbi)->bmiHeader;
                    widthSet = vfmt.biWidth;
                    heightSet = vfmt.biHeight;
                    fourcc = vfmt.biCompression;
                }
                delete []pbi;
            }
        }
        // And alternative way in case of failure.
        if( widthSet == 0 || heightSet == 0 )
        {
            widthSet = status.uiImageWidth;
            heightSet = status.uiImageHeight;
        }

    }
    return capWnd != 0;
}
//General connection method
BOOL	CAviCap::_connect2Driver(int indx)
{
	CHECKWIN();	
	if(indx<0||indx>_totalDrv())
		{
		TRACE("CAviCap Window connection failed: illegal driver index\n");
		iLastError=CAP_ILLEGAL_DRIVERID;
		return FALSE;
		}
	 AfxGetApp( )-> DoWaitCursor( 1 );
	
	//connect via VFW
	BOOL ret=capDriverConnect(GetSafeHwnd(), indx);
	checkQuit();
		
	if(ret)
	{
	//starts gathering of driver information
	 	_curDriver=indx;
		if(!_getCaps()||
		   !_getSetup()||
		   !_getStatus()||
		   !_getFormat())
		   	{
		   	iLastError=CAP_INIT_FAILED;
		   	ret=FALSE;
			}
		else
			{
			//try to make window unvisible befor testing
			BOOL vsbl=IsWindowVisible();
			if(vsbl)	ShowWindow(SW_HIDE);
	
			//Slow or fast connection?
			if(!m_DoQuickConnection) {
			 //OK. We have enough time to test driver :-)
			 UP_THR();

			 #ifdef	ON_CONNECT_TEST_BIBITSCOUNT
				_testBiBitsCount();
			 #endif
			 checkQuit();

			 #ifdef ON_CONNECT_CHECK_VALIDFORMATS
				_testValidFormats();
			 #endif
			 checkQuit();

			 #ifdef DEFAULT_FORCE_SINGLE_FRAME
				_testInternalBuffers();
			 #endif
			 checkQuit();
			 DN_THR();
			}
			//else skip testing
				
		// Setup default capture parameters
		// OPTIONAL
		#ifdef DEFAULT_FORCE_SINGLE_FRAME
			capSetCallbackOnFrame(GetSafeHwnd(),(LPVOID)_1FrameCallbackProc);
			_1FrameCallBackInstalled = TRUE;
		#else
			capSetCallbackOnFrame(GetSafeHwnd(), _defaultFrameCallbackProc);
			capPreviewRate(GetSafeHwnd(), _previewRate);
		#endif
		
		#ifdef DEFAULT_USED_DOSMEMORY
			_captureParms.wNumVideoRequested=1;
			_captureParms.fUsingDOSMemory=TRUE;
		#endif	

		#ifdef DEFAULT_STEP_CAPTUREAT2X
			_captureParms.fStepCaptureAt2x=TRUE;
			_captureParms.wStepCaptureAverageFrames=3;
		#endif
		
		_captureParms.dwRequestMicroSecPerFrame=20000;
		_captureParms.fYield = TRUE;
		capCaptureSetSetup (GetSafeHwnd(), &_captureParms, sizeof CAPTUREPARMS);
		capCaptureGetSetup (GetSafeHwnd(), &_captureParms, sizeof CAPTUREPARMS);		

		if(vsbl)	ShowWindow(SW_SHOW); //restore
		}//end else
		
	}
	else
	{
	AfxGetApp( )-> DoWaitCursor( 0 );
	TRACE("Connection to Capure Driver Failed\n");
	iLastError=CAP_CONNECTION_FAILED;
	return FALSE;
	}
	 
	if(ret) TRACE("Connected to <%s: %s>\n",GetDriverName(),GetDriverVer());

	else	  TRACE("Connection (phase 2) to Capure Driver Failed\n");
	
	if(!ret)	Disconnect();
	
	return ret;
}
		int   
			STVideoCapture::Initialize
			( 
            HWND hwndParentWindow, // This must be non-null
            STVideoCaptureFormat videoCaptureFormat,
            int capturePeriodMilliseconds,
			STVideoCaptureClient * pSTVideoCaptureClient
			)
		{
			(*this).Clear();




            // Validate capture format
            int captureWidth = 0;
            int captureHeight = 0;
            switch (videoCaptureFormat)
            {
			case BGR320x240: { captureWidth = 320; captureHeight = 240; } break;
            }

            if ((0 == captureWidth) || (0 == captureHeight))
            {
                printf( "Invalid capture format." );
                (*this).Clear();
                return (FALSE);
            }
            (*this).mSTVideoCaptureFormat = videoCaptureFormat;




            // We create a capture window only because we are required to create
            // such a window to use the Video for Windows (VFW32) API.  We make
            // this window tiny to keep it out of the way of our application.
            // For our purposes, this window is simply a necessary interface to
            // VFW functionality.
            (*this).mHWNDCapture =
                capCreateCaptureWindowA
                (
                    "STVideoCapture Window",
                    (WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS), // style
                    0, // x
                    0, // y
                    4, // width
                    4, // height
                    hwndParentWindow, // Parent window : This must be non-null
                    0 // nID
                );



			if (((HWND)(0)) == (*this).mHWNDCapture)
			{ 
                printf( "Failed to create video capture window." );
                DestroyWindow( (*this).mHWNDCapture );
                (*this).Clear();
                return (FALSE);
			}




			(*this).mCapDriverConnectStatus = capDriverConnect( (*this).mHWNDCapture, 0 );

            if (0 == (*this).mCapDriverConnectStatus)
            {
                printf( "Failed to connect to video driver." );
                DestroyWindow( (*this).mHWNDCapture );
                (*this).Clear();
                return (FALSE);
            }



			CAPDRIVERCAPS  capdrivercaps;
			memset( (&(capdrivercaps)),   0,  sizeof(capdrivercaps) );
			capDriverGetCaps( (*this).mHWNDCapture, &(capdrivercaps), sizeof(capdrivercaps) );




			//capDlgVideoFormat( mHWNDCapture );
			//capDlgVideoSource( mHWNDCapture );  // Source; Brightness, Contrast, Saturation, Exposure



            // Allocate a local buffer to store capture data
            int bytesPerPixel = 3;
            switch (videoCaptureFormat)
            {
			case BGR320x240: { bytesPerPixel = 3; } break;
            }
            int totalImageBytes = 0;
            totalImageBytes = (captureHeight * (captureWidth * bytesPerPixel));
            (*this).mBGRData = (unsigned char *) malloc( totalImageBytes );
			memset( (*this).mBGRData,   0,  totalImageBytes );



			// Set the video stream callback function
			(*this).mpSTVideoCaptureClient = pSTVideoCaptureClient;
			capSetCallbackOnFrame( (*this).mHWNDCapture, STVideoCapture::CommonCaptureCallback );


			// Set the preview rate in milliseconds
            (*this).mCapturePeriodMilliseconds = capturePeriodMilliseconds;
            capPreviewRate( (*this).mHWNDCapture, capturePeriodMilliseconds );


			// Disable preview mode
			capPreview( (*this).mHWNDCapture, FALSE );


			// Setup the data we want returned to us
			BITMAPINFO  capbitmapinfo;
			memset( &(capbitmapinfo), 0, sizeof(BITMAPINFO) );
			capbitmapinfo.bmiHeader.biSize           = sizeof(BITMAPINFOHEADER);
			capbitmapinfo.bmiHeader.biWidth          = captureWidth;
			capbitmapinfo.bmiHeader.biHeight         = captureHeight;
			capbitmapinfo.bmiHeader.biPlanes         =  1;
			capbitmapinfo.bmiHeader.biBitCount       = 24;
			capbitmapinfo.bmiHeader.biCompression    = BI_RGB;
			capbitmapinfo.bmiHeader.biSizeImage      = totalImageBytes;
			capbitmapinfo.bmiHeader.biXPelsPerMeter  = 100;
			capbitmapinfo.bmiHeader.biYPelsPerMeter  = 100;

			BOOL setVideoFormatResult = FALSE;
			setVideoFormatResult = capSetVideoFormat( (*this).mHWNDCapture, &(capbitmapinfo), sizeof(BITMAPINFO) );

            if (FALSE == setVideoFormatResult)
            {
                printf( "Failed to set the desired video capture format." );
                capSetCallbackOnFrame( (*this).mHWNDCapture, NULL ); // disable the callback function
                DestroyWindow( (*this).mHWNDCapture );
                (*this).Clear( );
                return (FALSE);
            }


			return( TRUE );
		} 
예제 #11
0
	void CSoCProjectView::OnInitialUpdate()
	{
		CScrollView::OnInitialUpdate();

		CSize sizeTotal;
		// TODO: 이 뷰의 전체 크기를 계산합니다.
		sizeTotal.cx = 640;
		sizeTotal.cy = 480;
		SetScrollSizes(MM_TEXT, sizeTotal);

		CSoCProjectDoc*pDoc = GetDocument();
		// TODO: 여기에 생성 코드를 추가합니다.
		RECT r;
		GetClientRect(&r);
		pDoc->m_hCamWnd = capCreateCaptureWindow(
			_T("Capture Window"), WS_CHILD | WS_VISIBLE, 5, 5, r.right-5, r.bottom-5, this->m_hWnd, NULL);

		// 설치된 디바이스를 순서로 0 ~ 9까지의 카메라를 지정 할 수 있다.
		if(!capDriverConnect(pDoc->m_hCamWnd, 0)) AfxMessageBox(_T("웹캠 인식 실패 ㅠㅠ"));

		// 현재 드라이버 정보에 관한 내용 얻어오기
		capDriverGetCaps(pDoc->m_hCamWnd, &pDoc->m_psCapsInfo, sizeof(pDoc->m_psCapsInfo));

		//비디오 포맷 변환을 지원하는지 확인한다.
		if(pDoc->m_psCapsInfo.fHasDlgVideoFormat) {
			// 비디오 포맷 변환을 지원하면 아래 함수를 호출한다.
			// 호출되는 함수는 새로운 다이얼로그를 호출하고 해상도와 포맷형식, 프레임 버퍼크기등을 지정할 수 있다.
			// 이때, 지원되지 않는 비디오포멧을 설정하면 검정 화면을 보게될 것이야...
			capDlgVideoFormat(pDoc->m_hCamWnd);
		}

		// m_psCapsInfo.fHasOverlay에서 overlay가 지원이 되지 않으면(=0) 사용 할 수 없다.
		if(pDoc->m_psCapsInfo.fHasOverlay) {
			// 하드웨어 오버레이는 시스템 부하를 줄여준다.(optioinal)
			capOverlay(pDoc->m_hCamWnd, FALSE);
		}

		// BITMAPINFO 설정
		capGetVideoFormat(pDoc->m_hCamWnd, &pDoc->m_BTMInfo, sizeof(pDoc->m_BTMInfo));

		// 1/1000 단위로 영상이 출력된다.
		capPreviewRate(pDoc->m_hCamWnd, 1);

		// 프리뷰 영상을 재생한다.
		capPreview(pDoc->m_hCamWnd, TRUE);

		CAPTUREPARMS cp;     
	
		capCaptureGetSetup(pDoc->m_hCamWnd, &cp, sizeof(cp) );	// get the current defaults      
	
		cp.dwRequestMicroSecPerFrame = 1;					// Set desired frame rate     
		cp.fMakeUserHitOKToCapture   = FALSE;
		cp.fYield                    = TRUE;                // we want capture on a background thread.
		cp.wNumVideoRequested        = (WORD) 1;			// we may get less than this - no problem
		cp.fCaptureAudio             = FALSE;     
		cp.vKeyAbort                 = 0;                   // If no key is provided, it won't stop...
		cp.fAbortLeftMouse           = FALSE;
		cp.fAbortRightMouse          = FALSE;
		cp.fLimitEnabled             = FALSE;				// we want to stop     
		cp.fMCIControl               = FALSE;
	
		capCaptureSetSetup(pDoc->m_hCamWnd, &cp, sizeof(cp) ); 
		
		capSetCallbackOnVideoStream(pDoc->m_hCamWnd, VideoCallbackProc);
		capSetCallbackOnFrame(pDoc->m_hCamWnd, VideoCallbackProc);
	}
예제 #12
0
long __stdcall DlgProc ( HWND hWnd , unsigned msg , unsigned wParam , long lParam )
{ 
   switch(msg)
   {
      case WM_INITDIALOG: 
			//hEdit = GetDlgItem( hWnd , I_EDIT );  
			//GetClientRect( hEdit , &rect );
			hWndCap = capCreateCaptureWindow ( NULL, WS_CHILD | WS_VISIBLE , 0, 0, 320, 240, hWnd, 1235 );
			//hWndCap = capCreateCaptureWindow ( NULL, WS_CHILD | WS_VISIBLE , 0, 0, (rect.right-rect.left ), (rect.bottom-rect.top), hEdit, 1235);
						
			// вручную заполняем структуру CapVar
			ZeroMemory( &CapVar, sizeof(COMPVARS) );   
			CapVar.cbSize = sizeof(COMPVARS);
			CapVar.dwFlags = ICMF_COMPVARS_VALID;   
			CapVar.cbState = 0;   
			CapVar.fccHandler = mmioFOURCC( 'x', '2', '6', '4' );   
			CapVar.fccType = ICTYPE_VIDEO;

			// открываем декомпрессор (долго)
			CapVar.hic = ICOpen( ICTYPE_VIDEO, CapVar.fccHandler, ICMODE_COMPRESS ); 

			hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)SendThread, NULL, 0, 0 );
						
			return -1 ;

      case WM_COMMAND:
			switch(LOWORD(wParam))			
			{
				case I_BUTTON_CONN :

					if( !capDriverConnect( hWndCap, 0 ) )
               {
                  EndDialog ( hWnd, 0 );
                  return -1;
               }
									
					capCaptureGetSetup( hWndCap, &CapParms, sizeof(CAPTUREPARMS) );        
   
					CapParms.dwRequestMicroSecPerFrame = 66000;    
					CapParms.fLimitEnabled = FALSE;     
					CapParms.fCaptureAudio = FALSE;    
					CapParms.fMCIControl = FALSE;     
					CapParms.fYield = TRUE;      
					CapParms.vKeyAbort = VK_ESCAPE;    
					CapParms.fAbortLeftMouse = FALSE;    
					CapParms.fAbortRightMouse = FALSE;    
					capCaptureSetSetup( hWndCap, &CapParms, sizeof(CAPTUREPARMS) );    
     
					capPreviewScale( hWndCap, 1 );     
					capPreviewRate( hWndCap, 66 );     
					capPreviewScale( hWndCap, FALSE );    
					capPreview( hWndCap, 1 );    
									
					//added by jimmy 

					// OPTIONAL STEP: Setup resolution
					capGetVideoFormat( hWndCap, &InputBmpInfo ,sizeof(InputBmpInfo) );
					//InputBmpInfo.bmiHeader.biWidth = 320; //(rect.right-rect.left );
					//InputBmpInfo.bmiHeader.biHeight = 240; //(rect.bottom-rect.top);
					//InputBmpInfo.bmiHeader.biBitCount = 24;
					capSetVideoFormat( hWndCap, &InputBmpInfo, sizeof(InputBmpInfo) );
					//capDriverDisconnect (hWndCap, 0);//Can we do better?
					//capDriverConnect (hWndCap, 0);

					capSetCallbackOnFrame( hWndCap, FrameCallBack ); 									

					if(CapVar.hic > 0 )   
					{  
						OutFormatSize = ICCompressGetFormatSize( CapVar.hic, &InputBmpInfo.bmiHeader );   // BITMAPINFO возвращает размер структуры исходных данных InputBmpInfo
						ICCompressGetFormat( CapVar.hic, &InputBmpInfo.bmiHeader, &OutputBmpInfo.bmiHeader );   //  заполняет структуру получаемых данных OutputBmpInfo
						OutBufferSize = ICCompressGetSize( CapVar.hic, &InputBmpInfo.bmiHeader, &OutputBmpInfo.bmiHeader );   // максимальный размер одного сжатого кадра (полученного)
						ICSeqCompressFrameStart( &CapVar, &InputBmpInfo );  // начало сжатия 
					}

					break;

				case I_BUTTON_EXIT :

					ICSeqCompressFrameEnd(&CapVar);   // конец сжатия
					ICCompressorFree(&CapVar);   
					ICClose(CapVar.hic);  

					capPreview( hWndCap , false );		
					capDriverDisconnect( hWndCap );

					EndDialog ( hWnd , 0 ) ;									
					break;

			}
		   return -1 ;	

      case WM_CLOSE :

			ICSeqCompressFrameEnd(&CapVar);   // конец сжатия
			ICCompressorFree(&CapVar);   
			ICClose(CapVar.hic);  

			capPreview( hWndCap , false );		
			capDriverDisconnect( hWndCap );
				
			EndDialog ( hWnd , 0 ) ;
         return -1 ;

   }

   return 0 ;
}