全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2752
推到 Plurk!
推到 Facebook!

如何使用DirectShow實現Zoom in/out?

缺席
sunwingman
一般會員


發表:26
回覆:47
積分:14
註冊:2008-05-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-06-28 18:17:26 IP:140.96.xxx.xxx 訂閱

想請教各位前輩,

我現在有一台羅技的webcam,我只灌他的驅動程式,不灌他的應用程式
也就是說我不能用他的應用程式去調整焦距、亮度以及相關參數

那該怎麼應用DirectShow去實現 Zoom in/out 呢?

麻煩各位前輩了,感謝~

附上我目前的程式進度:(能選擇webcam的解析度,並且能擷取靜態影像)

[code cpp]
void __fastcall TMainFm::CameraStart()
{
//Application->ProcessMessages(); //check...
FilterGraph->ClearGraph();
FilterGraph->Active = false;
Filter->BaseFilter->Moniker = SysDev->GetMoniker(0);
FilterGraph->Active = true;

ICaptureGraphBuilder2 *Graph = NULL; //Graph 宣告
IBaseFilter *SourceFilter = NULL; //soucefilter 宣告
IBaseFilter *VideoFilter = NULL; //VideoFilter 宣告

CheckDSError(FilterGraph->QueryInterface(IID_ICaptureGraphBuilder2, &Graph));
CheckDSError(VideoWindow->QueryInterface(IID_IBaseFilter, &VideoFilter));
CheckDSError(Filter->QueryInterface(IID_IBaseFilter, &SourceFilter));

//改變解析度的程式碼---------------
TPinList *PinList=new TPinList(SourceFilter);
TEnumMediaType *VideoMediaTypes=new TEnumMediaType(PinList->First());
IAMStreamConfig *iconfig = NULL;
CheckDSError(PinList->First()->QueryInterface(IID_IAMStreamConfig,(void **)&iconfig));

//int index=ComboBox2->ItemIndex;
//VideoMediaTypes->Items[解析度號碼]
iconfig->SetFormat(VideoMediaTypes->Items[webcam_idx]->AMMediaType); //logitech QuickCam Orbit AF
//編號19:1280x1024 24bit
//編號22:1600x1200 24bit


delete PinList;
delete VideoMediaTypes;
//----------------------------------

//擷取Stream的程式碼---------------
IBaseFilter *SampleFilter=NULL;
CheckDSError(SampleGrabber1->QueryInterface(IID_IBaseFilter,&SampleFilter));
//----------------------------------

Graph->RenderStream(&PIN_CATEGORY_PREVIEW, NULL, SourceFilter, SampleFilter, VideoFilter);
//Graph->RenderStream(&PIN_CATEGORY_PREVIEW, NULL, SourceFilter, NULL, VideoFilter);

FilterGraph->Play();
Graph->Release();
VideoFilter->Release();
SourceFilter->Release();
SampleFilter->Release();

}
//---------------------------------------------------------------------------

void __fastcall TMainFm::SampleGrabber1Buffer(TObject *sender,
double SampleTime, Pointer pBuffer, int BufferLen)
{
Application->ProcessMessages();
Image[0]->Canvas->Lock();
SampleGrabber1->GetBitmap(Image[0]->Picture->Bitmap, pBuffer, BufferLen);
Buffer->Assign(Image[0]->Picture->Bitmap);
//預覽時的框框
Image[0]->Canvas->Pen->Color=clLime;
Image[0]->Canvas->Pen->Width=15;
//Image[0]->Canvas->Pen->Mode=pmNotXor;
Image[0]->Canvas->Brush->Style=bsClear;
Image[0]->Canvas->Rectangle(150,200,1110,1000); //1.2的比例

if(IsCapture)
{
Buffer->SaveToFile(ExtractFilePath(Application->ExeName) "Capture" IntToStr(ShotCount) ".bmp"); //抓圖
IsCapture=false;
}

Image[0]->Canvas->Unlock();

}
//---------------------------------------------------------------------------

[/code]


sunwingman
一般會員


發表:26
回覆:47
積分:14
註冊:2008-05-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-07-19 10:52:52 IP:140.96.xxx.xxx 訂閱
不知道各位前輩有人試過嗎?
還是說Zoom in/out這個功能,只能用廠商提供的SDK才有辦法作到
DirectShow是辦不到的?
煩請大家不吝賜教,感謝!!!
sunwingman
一般會員


發表:26
回覆:47
積分:14
註冊:2008-05-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-09-16 00:46:35 IP:221.169.xxx.xxx 訂閱
我想這個問題應該是得不到答案了
我自己再努力試試看吧
如果有結果我也會不吝跟各位分享
希望這個論壇能有更多的互動...
sandyl39
一般會員


發表:0
回覆:12
積分:17
註冊:2003-02-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-09-29 11:11:39 IP:60.248.xxx.xxx 訂閱
你可以試試看利用讀取這個device的屬性...
一般而言...廠商都會將屬性頁開放出來給directshow...
先試著看可否get 屬性...
如果可以 get到...就可以變動了...
sunwingman
一般會員


發表:26
回覆:47
積分:14
註冊:2008-05-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2012-02-09 10:50:32 IP:140.96.xxx.xxx 訂閱
 Hello,感謝您回覆

其實我後來是直接在Buffer裡面作影像的處理,來達到zoom in/out的效果

以下是我程式碼的片段,跟你分享

void __fastcall TForm1::SampleGrabber1Buffer(TObject *sender,
double SampleTime, Pointer pBuffer, int BufferLen)
{
Application->ProcessMessages();
CaptureImage->Canvas->Lock();
SampleGrabber1->GetBitmap(CaptureImage->Picture->Bitmap, pBuffer, BufferLen);
GlobalBmp->Assign(CaptureImage->Picture->Bitmap);
Image1->Picture->Bitmap->Assign(CaptureImage->Picture->Bitmap);
Graphics::TBitmap *Temp = new Graphics::TBitmap();
Temp->Width =ImgW-Scale*2;
Temp->Height =(ImgW-Scale*2)*Rate;
Temp->PixelFormat=pf24bit;
int bias=Scale*Rate;
Byte *ptr=NULL;
Byte *gptr=NULL;
for(int y=bias;y
{
ptr = (Byte*)Image1->Picture->Bitmap->ScanLine[y];
gptr = (Byte*)Temp->ScanLine[y-bias];
for(int x=Scale; x
{
gptr[(x-Scale)*3] = ptr[x*3];
gptr[(x-Scale)*3 1] = ptr[x*3 1];
gptr[(x-Scale)*3 2] = ptr[x*3 2];
}
}
Image1->Stretch=true;
Image1->Picture->Bitmap->Assign(Temp);
delete Temp;
Temp=NULL;
CaptureImage->Canvas->Unlock();
}

void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
int pos,pos_t,t1,t2;
pos = ScrollBar1->Position;
pos_t = pos*20;
t1 = pos_t*2;
t2 = ImgW-100;
if(t1
Scale=pos_t;
else
ScrollBar1->Position = pos-1;
}
編輯記錄
sunwingman 重新編輯於 2012-02-08 19:51:18, 註解 無‧
sunwingman 重新編輯於 2012-02-08 19:52:30, 註解 無‧
sunwingman 重新編輯於 2012-02-08 19:53:13, 註解 無‧
系統時間:2024-04-25 15:41:10
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!