Autor Beitrag
bbfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Do 03.05.07 07:02 
Hallo Leute!

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

ausblenden 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: 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 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Do 03.05.07 08:31 
Hab ähnlich proceduren von dir gefunden..
Benutze jetzt:

ausblenden 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 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: 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 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Do 03.05.07 10:14 
habe einer deiner SourceCodes mal ausprobiert in einer separaten Application:

www.delphi-forum.de/...mcapsetcallbackframe

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

Die Priview geht.
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Do 03.05.07 12:48 
LÖSUNG:

ausblenden 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.