PDA

View Full Version : problem with frame grabber card DFG/SV1



Stefan Ey
December 13, 2005, 09:11:44
Hello ,

i have written a program in delphi 5.0 and uses a firewire camera (cs8850dif). The program works normaly and i can save images. Now i use a frame grabber card (DFG/SV1) with the same program/code and when i want save the image i get the following error message:

"An option is not avaible, e.g. you called setFlipH and the VideoCaptureDevice does not supporting flipping."

When i change the "LiveCaptureContinuous" property from true to false, i can save images without error message but the "ImageAvaible"-Event will never throw so that i blind.

I have tryed the 2.0 and new 3.0 activex control, its the same behavior.

Here are my questions:

a) is it a bug of the activex control or the card driver?

b) have i make false settings?

c) gives a workaround?

Thanks
Stefan Ey


Here is the code i use to initialize the device, start the live running,
show the image on screen and snap a image to file on hard disk.



{-----------------------------------------------------------------------}

procedure TfrmMain.acInitExecute(Sender: TObject);
const
CAM_SETTINGS_FILE_NAME = 'camera.settings';
begin
if FileExists(CAM_SETTINGS_FILE_NAME) then
IcImage.LoadDeviceStateFromFile(CAM_SETTINGS_FILE_ NAME, true);
if not IcImage.DeviceValid then
IcImage.ShowDeviceSettingsDialog;

if IcImage.DeviceValid then begin
fr.Image.Width := IcImage.ImageWidth;
fr.Image.Height := IcImage.ImageHeight;
IcImage.LiveDisplay := false;
IcImage.LiveCaptureLastImage := false;
IcImage.LiveCaptureContinuous := true;
IcImage.MemoryRingBufferSize := 10;
IcImage.SaveDeviceStateToFile(CAM_SETTINGS_FILE_NA ME);
acStartLive.Enabled := true;
acStartLive.Execute;
end; //if
acInit.Enabled := not IcImage.DeviceValid;
acStartLive.Enabled := IcImage.DeviceValid and not IcImage.LiveVideoRunning;
acStopLive.Enabled := IcImage.DeviceValid and IcImage.LiveVideoRunning;
acSnap.Enabled := IcImage.DeviceValid and IcImage.LiveVideoRunning;
end;

{-----------------------------------------------------------------------}

procedure TfrmMain.IcImageImageAvailable(Sender: TObject; BufferIndex: Integer);
var
hDIB: HGLOBAL;
pPixel: PCHAR;
pDIB: PCHAR;
bitmapinfo: Windows.BITMAPINFO;
iWidth, iHeight: integer;
begin
IcImage.ImageBuffers.Item[BufferIndex].Lock();
hDIB := IcImage.ImageBuffers.Item[BufferIndex].GetDib();

pDIB := GlobalLock(hDIB);
Move(pDIB^, bitmapinfo, sizeof(Windows.BITMAPINFO));
pPixel := pDIB + sizeof(bitmapinfo) - 4;

iWidth := bitmapinfo.bmiHeader.biWidth;
iHeight := bitmapinfo.bmiHeader.biHeight;

SetStretchBltMode(fr.Image.Canvas.Handle, COLORONCOLOR);
StretchDIBits(fr.Image.Canvas.Handle,
0, 0, iWidth, iHeight, 0, iHeight, iWidth, iHeight,
pPixel, bitmapinfo, DIB_RGB_COLORS, SRCCOPY);

fr.Image.Refresh;
GlobalUnlock(hDIB);
GlobalFree(hDIB);

IcImage.ImageBuffers.Item[BufferIndex].UnLock();
end;

{-----------------------------------------------------------------------}

procedure TfrmMain.acStartLiveExecute(Sender: TObject);
begin
if IcImage.DeviceValid and not IcImage.LiveVideoRunning then begin
fr.Image.Free;
fr.Image := TImage.Create(fr);
fr.Image.parent := fr.pImage;
fr.Image.Top := 5;
fr.Image.Left := 5;
fr.Image.Width := IcImage.ImageWidth;
fr.Image.Height := IcImage.ImageHeight;
IcImage.LiveStart;
acStartLive.Enabled := not IcImage.LiveVideoRunning;
acStopLive.Enabled := IcImage.LiveVideoRunning;
acSnap.Enabled := IcImage.LiveVideoRunning;
end;
end;

{-----------------------------------------------------------------------}

procedure TfrmMain.acSnapExecute(Sender: TObject);
begin
if IcImage.DeviceValid and IcImage.LiveVideoRunning then begin
IcImage.MemorySnapImage;
IcImage.MemorySaveImage('test.bmp');
acStartLive.Enabled := IcImage.DeviceValid and not IcImage.LiveVideoRunning;
acStopLive.Enabled := IcImage.DeviceValid and IcImage.LiveVideoRunning;
acSnap.Enabled := IcImage.DeviceValid and IcImage.LiveVideoRunning;
end;
end;

Stefan Geissler
December 13, 2005, 11:52:10
Stefan,

Normally MemorySnapImage should do nothing, if LiveCaptureContinuous is set to true. But it seems it throws an exception.
To avoid this, insert following code:


procedure TfrmMain.acSnapExecute(Sender: TObject);
begin
if IcImage.DeviceValid and IcImage.LiveVideoRunning then begin
{ IC 2.1 }
IcImage.ImageBuffers.Item[IcImage.ImageBuffers.CurrentIndex].SaveAsBitmap( 'test2.bmp', ICRGB24);

{ IC 3.0 }
IcImage.ImageActiveBuffer.SaveAsBitmap( 'test.bmp', ICRGB24);

acStartLive.Enabled := IcImage.DeviceValid and not IcImage.LiveVideoRunning;
acStopLive.Enabled := IcImage.DeviceValid and IcImage.LiveVideoRunning;
acSnap.Enabled := IcImage.DeviceValid and IcImage.LiveVideoRunning;
end;
end;

(IC 3.0)
This makes sure that you get the last image buffer, that has been filled.