Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.12.10;
Скачать: CL | DM;

Вниз

Изменение размера изображения при видеозахвате.   Найти похожие ветки 

 
Devider ©   (2006-04-26 11:01) [0]

Здравствуйте, Мастера, требуется ваша помощь!
Захватываю изображение с камеры. В качестве примера чтобы разобраться взял пример ASF Capture из DsPack. Изображение получается по умолчанию 320*240 (на глазок). Необходимо выставить большее (хотелось бы 720*576 или хотябы 640*480)
Делаю это таким способом:

procedure TVideoForm.SetPixelFormat(x, y: integer);
var fBuilder : ICaptureGraphBuilder2;
   fCapStreamConf :IAMStreamConfig;
   CapCount,CapSize,i:integer;
   currentMediaType:PAMMediaType;
   currentconfigcaps: VIDEO_STREAM_CONFIG_CAPS;
   result:HRESULT;

function IsMatchedConfigcaps(const Caps: VIDEO_STREAM_CONFIG_CAPS; const MediaType:PAMMediaType;SizeX,SizeY:Integer):boolean;
begin
 Result:=//IsEqualGUID(MediaType.majortype, VSC_Mediatype) and
         //((IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB24)            //or IsEqualGUID(MediaType.subtype,MEDIASUBTYPE_RGB32)));
         true;

  if result then
    Result:=(SizeX>=caps.MinOutputSize.cx) and  (SizeX<=caps.MaxOutputSize.cx) and
    (SizeY>=caps.MinOutputSize.cy) and  (SizeY<=caps.MaxOutputSize.cy);
end;

begin
 with FilterGraph as ICaptureGraphBuilder2 do
 begin
    if (Succeeded(FindInterface(@PIN_CATEGORY_CAPTURE,
                          @MEDIATYPE_Interleaved,
                          Filter as IBaseFilter,
                          IID_IAMStreamConfig,
                          fCapStreamConf))) then ShowMessage ("Interleaved");
//   не Interleaved поэтому идем дальше
    if (Succeeded(FindInterface(@PIN_CATEGORY_CAPTURE,
                          @MEDIATYPE_VIDEO,
                          Filter as IBaseFilter,
                          IID_IAMStreamConfig,
                          fCapStreamConf))) then ShowMessage ("Video");
 
   fCapStreamConf.GetNumberOfCapabilities(CapCount,CapSize);

   for I:=0 to CapCount-1 do begin  
     fCapStreamConf.GetStreamCaps(i,currentMediaType,currentconfigcaps);

     if not IsMatchedConfigcaps(currentconfigcaps, CurrentMediaType, x, y)
     then exit;
     ShowMessage("IsMatchedConfigcaps = true");
     with  CurrentMediaType^ do begin

       if IsEqualGUID(formattype,FORMAT_VideoInfo)
       then with pvideoInfoHeader(pbFormat)^ do  begin
            rcTarget:=Bounds(0,0,abs(X),abs(Y));
            bmiHeader.biWidth:=X;
            bmiHeader.biHeight:=Y;
        end
       else if IsEqualGUID(formattype,FORMAT_VideoInfo2)
       then with pvideoInfoHeader2(pbFormat)^ do  begin
          rcTarget:=Bounds(0,0,abs(X),abs(Y));
          bmiHeader.biWidth:=X;
          bmiHeader.biHeight:=Y;
         end
       else begin
         DeleteMediaType(currentmediaType);
         continue;  
       end;
       result:=fCapStreamConf.SetFormat(currentmediaType^);
     end; // matched mediatype
     DeleteMediaType(currentmediaType);
     if Succeeded(Result) then begin
       break;
       ShowMessage("Урряяя!!!");
     end;
   end;
 end;
end;

Проблема в том, что не срабатывает fCapStreamConf.SetFormat(), тоесть этого "Урряяя!!" я не вижу. Не могу понять почему. Помогите, пожалуйста, мастера! Мож у кого готовый пример есть... Буду благодарен за любую мысль!


 
WondeRu ©   (2006-04-27 14:16) [1]

в твое писанине, чтот не разобрался... я вот так делал:

procedure TVideoCapture.SetStreamConfig;
Var
 hr                  : HRESULT;
 pmt                 : PAMMediaType;
begin
 hr := (FFilterGraph as ICaptureGraphBuilder2).FindInterface(@PIN_CATEGORY_CAPTURE, @MEDIATYPE_Video, FFilter as IBaseFilter, IID_IAMStreamConfig, pVideoStreamConfig);
 if (hr <> NOERROR) Then raise Exception.Create("Unable create instance of IAMStreamConfig");

 hr := pVideoStreamConfig.GetFormat(pmt);        // current capture format
 if (hr <> NOERROR) Then
 Begin
   pVideoStreamConfig := Nil;
   raise Exception.Create("Unable get stream video format");
 End;

 VIDEOINFOHEADER(pmt.pbFormat^).bmiHeader.biWidth  := ImageWidth;
 VIDEOINFOHEADER(pmt.pbFormat^).bmiHeader.biHeight := ImageHeight;
 hr := pVideoStreamConfig.SetFormat(pmt^);
 if (hr <> NOERROR) then raise Exception.Create("Unable set stream video format");
end;



 
Devider ©   (2006-04-27 15:32) [2]

Я ее вот так чуток переделал.

function TVideoForm.SetStreamConfig(ImageWidth, ImageHeight: integer):boolean;
Var
hr                  : HRESULT;
pmt                 : PAMMediaType;
pVideoStreamConfig  : IAMStreamConfig;

begin
hr := (FilterGraph as ICaptureGraphBuilder2).FindInterface(@PIN_CATEGORY_CAPTURE, @MEDIATYPE_Video, Filter as IBaseFilter, IID_IAMStreamConfig, pVideoStreamConfig);
if (hr <> NOERROR) Then raise Exception.Create("Unable create instance of IAMStreamConfig");

hr := pVideoStreamConfig.GetFormat(pmt);        // current capture format
if (hr <> NOERROR) Then
Begin
  pVideoStreamConfig := Nil;
  raise Exception.Create("Unable get stream video format");
End;

VIDEOINFOHEADER(pmt.pbFormat^).bmiHeader.biWidth  := ImageWidth;
VIDEOINFOHEADER(pmt.pbFormat^).bmiHeader.biHeight := ImageHeight;
hr := pVideoStreamConfig.SetFormat(pmt^);
Result := true;
if (hr <> NOERROR) then result := false;

end;

Вызываю так (так ли надо?)
FilterGraph.Stop;
if SetStreamConfig(88,72) then ShowMessage("true");
FilterGraph.Play;

"true" я получаю, а картинка не меняется. Что я делаю не так?

Если разрешение поставить больше чем то, что у меня по умолчанию (320*240 вроде) получаю true, а на
FilterGraph.Play;
получаю:
-----------------
Project ASFCap.exe raised exception class EDirectShowException with message "Неопознанная ошибка  ($80004005).". Process stopped. Use Step or Run to continue.
-----------------


 
Devider ©   (2006-04-27 23:36) [3]

Фсе, разобрался вроде! Спасибо!



Страницы: 1 вся ветка

Текущий архив: 2006.12.10;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.037 c
8-1146395580
Gumus
2006-04-30 15:13
2006.12.10
Popupmenu


15-1164105040
TUser
2006-11-21 13:30
2006.12.10
АТА и обратная совместимость


2-1163934179
Lebedev
2006-11-19 14:02
2006.12.10
Ошибка «Данное имя устройства уже используется приложением в каче


2-1164489332
kami
2006-11-26 00:15
2006.12.10
Потокобезопасность TStringList


15-1163667927
DelphiLexx
2006-11-16 12:05
2006.12.10
Помогите подобрать цвет для заголовков групп grid a