Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - Frame Grabbing - Warum Zwischenablage? videocap.pas


bbfan - Do 03.05.07 07:02
Titel: Frame Grabbing - Warum Zwischenablage? videocap.pas
Hallo Leute!

Ich habe folgende procedure in die videocap.pas hinzugefügt:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure CapGrabSingleFrameBMP(bmps:TImage);
var
 m_hBmp : HWND;
 xWidth, xHeight: Integer;
 BitmapInfo: TBitmapInfo;
begin  
  FillChar(BitmapInfo, SizeOf(BitmapInfo), 0);  
  SendMessage(ghCapWnd, WM_CAP_GET_VIDEOFORMAT, SizeOf(BitmapInfo), Integer(@BitmapInfo));
  xWidth:=BitmapInfo.bmiHeader.biWidth;
  xHeight:=BitmapInfo.bmiHeader.biHeight;
 bmps.Picture.Bitmap.Width:=xWidth;
 bmps.Picture.Bitmap.Height:=xHeight;
 bmps.Picture.Bitmap.PixelFormat:=pf24Bit;
 capGrabFrame(ghCapWnd); // simple macro that sample a single frame from the  camera.
 capEditCopy(ghCapWnd);  // simple macro that edit a copy of the frame.
 bmps.Picture.Bitmap.LoadFromClipboardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
end;


Wie kann ich den Weg über die Zwischenablage umgehen?

Viele Grüße,
BBfan


Phantom1 - Do 03.05.07 08:17

Mit hilfe einer Callback function kommt man auch ohne die zwischenablage an die frames, suche mal nach WM_CAP_SET_CALLBACK_FRAME

mfg


bbfan - Do 03.05.07 08:31

Hab ähnlich proceduren von dir gefunden..
Benutze jetzt:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function FrameCallbackFunction(AHandle : hWnd; VIDEOHDR : TVideoHDRPtr): bool; stdcall;
var I : integer;
    AColor : array[1..4] of byte;
begin
  result := true;
    ConvertCodecToRGB(FCodec, VideoHDR^.lpData, @FBuf2,PicWidth, PicHeight);
    // da zu einem bottom-up-bitmap dekomprimiert wird, drehe ich die Daten nochmal rum
    for I := 1 to PicHeight do FBuf1[I] := FBuf2[PicHeight -(I-1)];
    // laden der fertigen Pixel-Daten nach FBitmap
    SetBitmapBits(FBitmap.Handle,PicWidth*PicHeight*SizeOf(DWord),@FBuf1);
    // + Code zur Untersuchung der Bildes, z.B.: Wenn ein bestimmter Pixel X/Y
    // (=0/0) des Pictures rot ist, dann schlage Alarm... (oder so)
    DWord(AColor) := FBitmap.Canvas.Pixels[0,0];
    if (AColor[1] > 150) and (AColor[2] < 100) and (AColor[3] < 100) then beep;
end;


Allerdings habe ich jetzt nur ein schwarze Bild in der Bitmap... FBuf2 ist voller "0"...


bbfan - Do 03.05.07 09:03

Das Problem scheint die "ConvertCodecToRGB" Funktion zu sein.
Da mein Stream bereits vcRGB ist, konvertiert er nicht, und somit beilbt Buf2 leer.

Das müsste man fixen...


bbfan - Do 03.05.07 10:14

habe einer deiner SourceCodes mal ausprobiert in einer separaten Application:

http://www.delphi-forum.de/viewtopic.php?t=57238&highlight=wmcapsetcallbackframe

Auch hier bekomme ich nur ein schwarzes Bild ....

Die Priview geht.


bbfan - Do 03.05.07 12:48

LÖSUNG:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
     if FCodec <> vcRGB then
      begin
        ConvertCodecToRGB(FCodec, VideoHDR^.lpData, @FBuf2,PicWidth, PicHeight);
        for I := 1 to PicHeight do FBuf1[I] := FBuf2[PicHeight -(I-1)];
        FBitmap.PixelFormat := pf32Bit;
        SetBitmapBits(FBitmap.Handle,PicWidth*PicHeight*SizeOf(DWord),@FBuf1);
      end else
       begin
        FBitmap.PixelFormat := pf24Bit;
        SetBitmapBits(FBitmap.Handle,VideoHDR^.dwBufferLength,VideoHDR^.lpData);
       end;



Entscheident ist, dass ein RGB Format mit 24bit dargestellt werden muss und ein YUV2RGB konvertiertes Bild in 32bit.