读取大恒采集卡c++代码
#ifndef _DAHENG_CARD_HEAD_ #define _DAHENG_CARD_HEAD_ #include"Daheng\CGVideo.h" #include"Daheng\CGVidEx.h" #pragma comment(lib, "CGVideo.lib") #pragma comment(lib, "CGVidEx.lib") class DaHengVideo { public: DaHengVideo() { initdata(); } ~DaHengVideo() { clear(); } void initdata() { pImage=NULL; m_CardID=1,m_PortID=2,m_OSC28M=0; m_Width=768,m_Height=576; m_inputX=0,m_inputY=0,m_inputW=768,m_inputH=576; m_Brightness=128,m_Contrast=128,m_Hue=80,m_Saturation=128; } bool setup(int w,int h,int CardID,int PortID,int OSC28M) { m_Width=w,m_Height=h; //--------------------------------------------------------------------------------------- m_size=m_Width*m_Height*3; pImage=new BYTE[m_size]; ////////////////////////////////////////////////////////////////////////// CGSTATUS status =BeginCGCard(m_CardID,&m_hcg); if(status!= CG_OK) { printf("init Card error! \n"); } CGSetVideoStandard(m_hcg,PAL); CGSetVideoFormat(m_hcg,RGB888); CGSetScanMode(m_hcg,FRAME); if(m_OSC28M) CGSelectCryOSC(m_hcg,CRY_OSC_28M); else CGSelectCryOSC(m_hcg,CRY_OSC_35M); VIDEO_SOURCE source; source.type = COMPOSITE_VIDEO; source.nIndex = m_PortID; CGSetVideoSource(m_hcg,source); CGSetInputWindow(m_hcg,m_inputX,m_inputY,m_inputW,m_inputH); CGSetOutputWindow(m_hcg,0,0,m_Width,m_Height); CGOpenSnapEx(m_hcg,SnapCallbackEx,this); CGStartSnapEx(m_hcg,m_size*((m_CardID-1)*2),TRUE,2); SetBrightness(m_Brightness); SetContrast(m_Contrast); SetHue(m_Hue); SetSaturation(m_Saturation); printf("DaHeng Card init Succssed \n"); return true; } void clear() { CGSTATUS m_stats=EndCGCard(m_hcg); if(m_stats ==CG_OK) { printf("DaHengCard Shutdown Sucssed!\n "); } if(pImage!=NULL) { delete [] pImage; pImage =NULL; } } void SetBrightness(long Brightness){m_Brightness=Brightness;CGAdjustVideo(m_hcg,BRIGHTNESS,m_Brightness);} void SetContrast(long Contrast){m_Contrast=Contrast;CGAdjustVideo(m_hcg,CONTRAST,m_Contrast);} void SetHue(long Hue){m_Hue=Hue;CGAdjustVideo(m_hcg,HUE,m_Hue);} void SetSaturation(long Saturation){m_Saturation=Saturation;CGAdjustVideo(m_hcg,SATURATION,m_Saturation);} void update() { if(m_Refrash) { m_Refrash=false; } } int GetW() { return m_Width; } int GetH() { return m_Height; } BYTE *GetPixels() { return pImage; } void draw(float x, float y) { //m_Image.draw(x,y); } void draw(float x, float y,float w,float h) { // m_Image.draw(x,y,w,h); } ////////////////////////////////////////////////////////////////////////// void Play() { CGStartSnapEx(m_hcg,m_size*((m_CardID-1)*2),TRUE,2); } void Stop() { CGStopSnapEx(m_hcg); } void Snap(int mNumber) { // if(m_Refrash)return; HANDLE handle = NULL; BYTE *pStaticBuffer=NULL; if(CG_SUCCESS(CGStaticMemLock(m_size*(mNumber+(m_CardID-1)*2),m_size,&handle,(VOID **)&pStaticBuffer))) { printf("wai get data \n"); if(CG_SUCCESS(CGDataTransform(pImage,pStaticBuffer,m_Width,m_Height,24,false))) { printf("get data \n"); m_Refrash=true; } } CGStaticMemUnlock(handle); } static int CALLBACK SnapCallbackEx(SNAP_INFO *pInfo) { DaHengVideo* pClass = (DaHengVideo*)(pInfo->pParam); pClass->Snap(pInfo->nNumber); printf("staic get \n"); return 1; } private: int m_CardID; int m_PortID; int m_Width; int m_Height; int m_size; HCG m_hcg; int m_OSC28M; BYTE* pImage; private: int m_Brightness,m_Contrast,m_Hue,m_Saturation; int m_inputX,m_inputY,m_inputW,m_inputH; bool m_Refrash; }; #endif