⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idsfalconframegrabber.cpp

📁 VideoMan (Video Manager) is an open-source C++ library that helps you developing video based applica
💻 CPP
字号:
#include <assert.h>

#include <windows.h>
#include "IDSFalconFrameGrabber.h"

/*
Code based on the IdsDemo sample program included in the FALCON SDK
*/
IDSFalconFrameGrabber::IDSFalconFrameGrabber(void)
{	
}

IDSFalconFrameGrabber::~IDSFalconFrameGrabber(void)
{
	is_FreeImageMem( g_hBoard, m_pcImageMem, m_nImageMemID );

	if (g_hBoard != NULL)
	{
		// free image mem
	//	is_FreeImageMem (g_hBoard, m_pcImageMem, m_nImageMemID);

		// close board
		INT ret = is_ExitBoard (g_hBoard);
	}

	g_hBoard = NULL;
}

INT IDSFalconFrameGrabber::colorModeFromDepth( PIXEL_FORMAT depth)
{
	switch (depth)
	{
	case GREY8:
		return IS_SET_CM_Y8;
		break;
	/*case 15:
		return IS_SET_CM_RGB15;
		break;
	case 16:
		return IS_SET_CM_RGB16;
		break;*/
	case RGB24:
	case BGR24:
		return IS_SET_CM_RGB24;
		break;
	case RGB32:
	case BGR32:
		return IS_SET_CM_RGB32;
		break;
	default:
		return -1;
		break;
	}
}

bool IDSFalconFrameGrabber::initBoard( const unsigned long &hids, VideoManInputFormat *aFormat )
{
	g_hBoard = (HIDS) hids;
	INT ret = is_InitBoard( &g_hBoard, NULL );

	if (ret == IS_SUCCESS)
	{
		// get board type (Falcon or Eagle)
		int m_nBoardType = is_GetBoardType( g_hBoard );
		if (m_nBoardType == IS_BOARD_TYPE_EAGLE)
			identification.friendlyName = "IDS - EAGLE";
		else if (m_nBoardType == IS_BOARD_TYPE_FALCON2)
			identification.friendlyName = "IDS - FALCON2";
		else if (m_nBoardType == IS_BOARD_TYPE_FALCON_PLUS)
			identification.friendlyName = "IDS - FALCON PLUS";
		else if (m_nBoardType == IS_BOARD_TYPE_FALCON_DUO)
			identification.friendlyName = "IDS - FALCON DUO";
		else if (m_nBoardType == IS_BOARD_TYPE_FALCON_QUATTRO)
			identification.friendlyName = "IDS - FALCON QUATTRO";
		else if (m_nBoardType == IS_BOARD_TYPE_EAGLE_DUO)
			identification.friendlyName = "IDS - EAGLE DUO";
		else if (m_nBoardType == IS_BOARD_TYPE_EAGLE_QUATTRO)
			identification.friendlyName = "IDS - EAGLE QUATTRO";
		else
			identification.friendlyName = "IDS - FALCON";
	}

	if ( aFormat != NULL )
	{
		colorMode = colorModeFromDepth( aFormat->getPixelFormatOut() );
		format.setPixelFormat( aFormat->getPixelFormatIn(), aFormat->getPixelFormatOut() );
	}
	else
	{
		colorMode = IS_SET_CM_RGB24;
		format.setPixelFormat( BGR24, BGR24 );
	}

	if ( colorMode == -1 || is_SetColorMode( g_hBoard, colorMode ) != IS_SUCCESS )
	{
        assert( false && "IDSFalconFrameGrabber::initBoard: Can't set color mode" );
		return false;
	}

	// calculate size of image memory to allocate	
	format.width = 768;
	format.height = 576;
	if ( aFormat )
	{
		format.width = aFormat->width;
		format.height = aFormat->height;
	}
	long m_lMemSize = (long) format.width * (long) format.height * (long) format.getBpp();

	//is_SetVideoMode (g_hBoard, IS_SET_VM_PAL);

	// allocate image memory

	ret = is_AllocImageMem( g_hBoard, format.width, format.height, format.getBpp()*8, &m_pcImageMem, &m_nImageMemID );
	if (ret != IS_SUCCESS)
    {
		assert( false && "IDSFalconFrameGrabber::initBoard: Can't allocate image memory" );
		return false;
    }

	// set this image memory active
	ret = is_SetImageMem (g_hBoard, m_pcImageMem, m_nImageMemID);
	if (ret != IS_SUCCESS)
	{
		assert( false && "IDSFalconFrameGrabber::initBoard: Can't set image memory" );
		return false;
	}

	// set the image size
	is_SetImageSize( g_hBoard, format.width, format.height );

	// create a device dependent bitmap
	/*CBitmap *m_pBMP = new CBitmap ();
    
	if (m_pBMP == NULL)
	{
		assert( false && "IDSFalconFrameGrabber::initBoard: Can't create BMP-Bitmap" );      
		return false;
	}

    // set width and height
    bm.bmType       = 0;                  
    bm.bmBitsPixel  = m_nAdjustedColorDepth;
    bm.bmWidth      = m_ImgXsiz;
    bm.bmHeight     = m_ImgYsiz;
    bm.bmWidthBytes = m_ImgXsiz * m_nBytesPixel;
    bm.bmPlanes     = 1;
    bm.bmBits       = NULL;     

    BOOL ret = m_pBMP->CreateBitmapIndirect (&bm);
    
	if ( !ret )
	{
		assert ("IDSFalconFrameGrabber::initBoard: Can't create BMP-Bitmap" );
		return;
	}*/

	is_SetDisplayMode( g_hBoard, IS_SET_DM_DIB );
		
	is_SetCaptureMode( g_hBoard, IS_SET_CM_FRAME );
	is_SetErrorReport( g_hBoard, IS_ENABLE_ERR_REP );
	is_CaptureVideo( g_hBoard, IS_WAIT );//IS_DONT_WAIT

	// set flag that the is_SaveImage / is_LoadImage stores the path if the
	// file save / file open dialog box is used
	is_BoardStatus( g_hBoard, IS_STORE_FILE_PATH, 1 );

	BOOL m_boLive = is_CaptureVideo( g_hBoard, IS_GET_LIVE );
	BOOL g_boLive = m_boLive;

	if ( aFormat != NULL )	
		*aFormat = format;

    /*identification.friendlyName = name;
	frameCaptured = false;
	
	identification.friendlyName = selectedName;
	format.width  = pvi->bmiHeader.biWidth;	format.height = pvi->bmiHeader.biHeight;	format.fps = referenceTime2fps( pvi->AvgTimePerFrame ); 	format.setPixelFormat( UNKNOWN, translateMEDIASUBTYPE( mediaType.subtype ) );

	if ( format.width<=0 || format.height<=0 )
	{
		freeDirectShow();
		return false;
	}
	if (format.fps<=0)
		format.fps=30;

	if ( aFormat != NULL )	
		*aFormat = format;
*/
	return true;
}

inline char *IDSFalconFrameGrabber::getFrame( bool wait)
{
	//is_FreezeVideo( g_hBoard, IS_WAIT );
	pixelBuffer = m_pcImageMem;	
	return pixelBuffer;
}


void IDSFalconFrameGrabber::releaseFrame()
{
	if (frameCaptured)
	{
	}
}


void IDSFalconFrameGrabber::play()
{

}


void IDSFalconFrameGrabber::pause()
{

}


void IDSFalconFrameGrabber::stop()
{

}


void IDSFalconFrameGrabber::showPropertyPage()
{

}

void IDSFalconFrameGrabber::getAvailableDevices( std::vector<inputIdentification> &deviceList  )
{
	int number;
	is_GetNumberOfBoards( &number );
	for ( int n = 0; n < number; ++n )
	{
		/*int info;
		ULONG ulValue;
		is_BoardStatus( (HIDS)n, info, ulValue );*/
		inputIdentification device;
		device.friendlyName = "IDS Falcon Frame Grabber";
		device.identifier = "IDS_FALCON_FRAME_GRABBER";
		device.serialNumber = n;		
		deviceList.push_back( device );
	}
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -