[DSPACK]CCD擷取影像至TImage元件上 |
尚未結案
|
psp67101
一般會員 發表:5 回覆:10 積分:3 註冊:2005-05-06 發送簡訊給我 |
[code cpp] void __fastcall TForm1::Button5Click(TObject *Sender) { CoInitialize(NULL); InitCaptureGraphBuilder(&pGraph, &pBuild); EnumerateVideoInputDevice(&pCap); pGraph->AddFilter(pCap,L"Capture Filter"); // 將攝影機加入 filter graph 中 IBaseFilter *pSG_Filter; hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pSG_Filter); hr = pGraph->AddFilter(pSG_Filter, L"SampleGrab"); // 將 Sample Grabber 加入 filter graph 中 IBaseFilter *pNull; hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pNull); hr = pGraph->AddFilter(pNull, L"NullRender"); // << --- SDK 錯誤更正 hr = pBuild->RenderStream( &PIN_CATEGORY_PREVIEW, // Connect this pin ... &MEDIATYPE_Video, // with this media type ... pCap, // on this filter ... pSG_Filter, // to the Sample Grabber ... pNull); // ... and finally to the Null Renderer. if(FAILED(hr)){ MessageBox(NULL,"Error","Error",MB_OK); } ISampleGrabber *pSG; hr = pSG_Filter->QueryInterface(IID_ISampleGrabber, (void**)&pSG); pSG->SetOneShot(FALSE); // [設定擷取屬性] 當收到一個 sample 時,是否要停止 graph pSG->SetBufferSamples(TRUE); // [設定擷取屬性] 是否要將 sample 放到內部 buffer 中 ZeroMemory(&am_media_type, sizeof(AM_MEDIA_TYPE)); am_media_type.majortype= MEDIATYPE_Video;//視頻流 am_media_type.formattype= FORMAT_VideoInfo; am_media_type.subtype= MEDIASUBTYPE_RGB24;//24位圖像 hr=pSG->SetMediaType(&am_media_type);//關聯介面 hr=pSG->SetBufferSamples(True); hr=pSG->GetConnectedMediaType(&am_media_type); HBITMAP Bitmap; BITMAPINFOHEADER bmphdr; BITMAPINFO BitmapInfo; VIDEOINFOHEADER *pVideoInfoHeader = (VIDEOINFOHEADER*)am_media_type.pbFormat; long nBufferSize = am_media_type.lSampleSize; long *pBuffer=(long*)malloc(nBufferSize); pSG->GetCurrentBuffer(&nBufferSize, (long*)&pBuffer); ZeroMemory(&pVideoInfoHeader, sizeof(VIDEOINFOHEADER)); CopyMemory(&pVideoInfoHeader, am_media_type.pbFormat, sizeof(pVideoInfoHeader)); ZeroMemory(&BitmapInfo, sizeof(BITMAPINFO)); CopyMemory(&BitmapInfo, &pVideoInfoHeader->bmiHeader, sizeof(pVideoInfoHeader->bmiHeader)); Bitmap=CreateDIBSection(0, (BITMAPINFO *)&BitmapInfo, DIB_RGB_COLORS, (void **)&pBuffer, 0, 0); pSG->GetCurrentBuffer(&nBufferSize, (long*)&pBuffer); Form1->Image1->Picture->Bitmap->Handle= Bitmap; pSG->Release(); // 用完 interface 後,釋放記憶體 // Step 5: 建立控制器用來執行我們的 graph filter hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); pControl->Run(); } [/code] 有錯誤在這一行,在 CopyMemory(&BitmapInfo, &pVideoInfoHeader->bmiHeader, sizeof(pVideoInfoHeader->bmiHeader)); 不知道要怎麼解決, 我想了好久到底要怎麼樣才能將Camera的影像擷取到Buffer再取出來做處理, 麻煩幫幫忙 |
qmlab
一般會員 發表:0 回覆:6 積分:11 註冊:2008-02-15 發送簡訊給我 |
[code cpp] [/code] 用TMemoryStream *stream; 處理影像Buffer很容易, 下面程式是我之前做影像辨識時從CCD截取影像至Buffer的片斷, 或許有幫助! static BITMAPFILEHEADER BitmapFileHead; static BITMAPINFOHEADER BitmapHead; static BITMAPINFO BitmapInfo; CAPSTATUS status; int BIHsize, byte; Byte *ptr; TMemoryStream *stream; stream=new TMemoryStream; //取得圖片資料 VideoStr=LPVIDEOHDR(lpVHdr); //取得CAP訊息 capGetStatus(_hCapWnd,&status,sizeof(status)) ; //取得圖片格式容量大小 BIHsize=capGetVideoFormatSize(_hCapWnd ); //取得圖片格式 代入 bitmapinfohead 內 capGetVideoFormat(_hCapWnd,&BitmapHead,BIHsize); capGetVideoFormat(_hCapWnd,&_BitmapInfo,sizeof(BITMAPINFO)); // 設定 BITMAPINFO //BitmapInfo.bmiHeader=BitmapHead; // 取得圖檔總容量 //stream->Size=sizeof(BITMAPFILEHEADER) sizeof(BITMAPINFOHEADER) BitmapHead.biSizeImage; stream->Size=sizeof(BITMAPFILEHEADER) sizeof(BITMAPINFOHEADER) _BitmapInfo.bmiHeader.biSizeImage; // 設定 BITMAPFILEHEAD BitmapFileHead.bfType=0x4D42; //總是 BM BitmapFileHead.bfSize=stream->Size; //該圖檔總大小 BitmapFileHead.bfOffBits=sizeof(BITMAPFILEHEADER) sizeof(BITMAPINFOHEADER); // 偏移至imagedata大小 // 將資料存入 memorystream stream->Position=0; stream->WriteBuffer(&BitmapFileHead,sizeof(BITMAPFILEHEADER)); stream->WriteBuffer(&_BitmapInfo,sizeof(BITMAPINFO)); (void*)ptr=stream->Memory; ptr = BitmapFileHead.bfOffBits; ////不要調色盤 Move(VideoStr->lpData,ptr,_BitmapInfo.bmiHeader.biSizeImage); // 存入完成 stream->Position=0; Bitmap->LoadFromStream(stream); delete(stream); capSetCallbackOnFrame(_hCapWnd,NULL); //停止callbackonframe
編輯記錄
qmlab 重新編輯於 2008-02-22 17:48:25, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |