PDA

View Full Version : DELPHI 7 and ICImaging



brüll
July 31, 2006, 12:28:10
Hi,

I got acces to the buffers and pixels with Delphi (Source Code below). Now I would like to ask

1. How gets it faster? I've got better experience with USB Cameras, they are even faster. This TIS devices are ridiculous slow.

2. How can I show extracted Pixel in Realtime on the Overlay Bitmap

3. Are there any drivers for the DFK 41BF02 camera, which can provide RGB24 or UVYV format with 640X480 Pixls in 2x2 binning??

Thanks

DELPHI 7 CODE:


unit uBuffers;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, ICImagingControl3_TLB, ComObj, Menus, ExtCtrls;
type
TForm1 = class(TForm)
ICImagingControl1: TICImagingControl;
MainMenu1: TMainMenu;
File1: TMenuItem;
Properties1: TMenuItem;
Settings1: TMenuItem;
Device1: TMenuItem;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Device1Click(Sender: TObject);
procedure Properties1Click(Sender: TObject);
procedure ICImagingControl1ImageAvailable(ASender: TObject;
BufferIndex: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
type
tRGB = record
r,g,b: byte;
end;
var
Form1 : TForm1;
ZoomValue : single;
FrameCount : integer = 0;
CurrentBuffer: ImageBuffer;
OB : OverlayBitmap;
ImageA : array [0..1280, 0..960] of tRGB;

implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
try
ICImagingControl1.LoadDeviceStateFromFile('device. xml',true);
except
ON EOleException do
begin
ICImagingControl1.ShowDeviceSettingsDialog();
if ICImagingControl1.DeviceValid = TRUE then
begin
ICImagingControl1.SaveDeviceStateToFile('device.xm l');
end;
end;
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
if ICImagingcontrol1.DeviceValid = True then
begin
{ZoomSettings}
ZoomValue:= ICImagingControl1.LiveDisplayZoomFactor;
ICImagingControl1.LiveDisplayDefault:= false;
//ICImagingControl1.LiveDisplayZoomFactor:= ZoomValue / 2;
// ICIMagingControl1.LiveCaptureContinuous:= true;
{ImageProcSettings}
// MaxY:= ICImagingControl1.ImageHeight - 1;
// MaxX:= ICImagingControl1.ImageWidth - 1;
ICImagingControl1.LiveDisplay:= false;
ICImagingControl1.LiveCaptureLastImage:= false;
ICImagingControl1.LiveCaptureContinuous:= true;
ICImagingControl1.Width:= ICImagingControl1.ImageWidth;
ICImagingControl1.Height:= ICImagingControl1.ImageHeight;
ICImagingControl1.LiveStart();
end;
end;
procedure TForm1.Device1Click(Sender: TObject);
begin
ICImagingControl1.LiveStop;
ICImagingControl1.ShowDeviceSettingsDialog;
ICImagingControl1.LiveStart;
end;
procedure TForm1.Properties1Click(Sender: TObject);
begin
ICImagingControl1.ShowPropertyDialog;
end;
procedure TForm1.ICImagingControl1ImageAvailable(ASender: TObject;
BufferIndex: Integer);
var
x,y,xm,ym : integer;
ImageData : OleVariant;
begin
CurrentBuffer:= ICImagingControl1.ImageActiveBuffer;
ImageData:= CurrentBuffer.GetImageData;
For x:= 0 to ICImagingControl1.ImageWidth - 1 do
For y:= 0 To ICImagingControl1.ImageHeight - 1 do
begin
ImageA[x,y].r:= ImageData[x * 3 + 2, y];
ImageA[x,y].g:= ImageData[x * 3 + 1, y];
ImageA[x,y].b:= ImageData[x * 3 + 0, y];
end;
CurrentBuffer.ReleaseImageData(ImageData);
ICImagingControl1.DisplayImageBuffer(CurrentBuffer );
end;

end.[/SIZE]

Johannes Vogel
July 31, 2006, 14:50:43
Hello,
I have a few questions:

1) What are you trying to do with " ImageA". As far as I can see, you are copying the image data from the IC buffer to your " ImageA". What is that good for. Why dont you use memcopy or just use the original IC buffer for your image processing. Before you do somthing with the buffer, you should lock it. As long as the buffer is locked, it will not get overwritten. If you are done with the buffer, you should unlock it.

2) There are several ways of doing it. I need more information to choose the best way. Haw many pixels will be manipulated from frame to frame (deleted and added to the overlay)?

3) We will soon release a frame filter that allows the images from the device to be scaled down.

BTW.: If you are get an error while restoring the device state from "device.xml", you opne the device selectiondialog and save the new device state to "device.xm l". You probably want to save it "device.xml" instead of "device.xm l".

brüll
July 31, 2006, 16:32:10
1. ImageA is for Convolution. You won't suggest to do this on your slow buffer? The convolved image shall be rewritten to the buffer. Thanks for the unlock thing. :D

2. approx. 400-5000 pixels, are deleted and 400 to 5000 will be added.

3. I would prefer a better driver, need the frame filter for other things. :(

Thanks, kind regards

Dan

Johannes Vogel
August 2, 2006, 14:14:18
I am sorry that I did not see the problem in the first place. The array returned by .GetImageData is slow in Delphi. This should be used in VisualBasic or in cases where speed does not matter. For fast buffer access, you can get a pointer from .ImageDataPtr. Here is a sample code that shows how to access the bufffer in a fast way from Delphi:

procedure TForm1.ICImagingControl1ImageAvailable(Sender: TObject;
BufferIndex: Integer);
var
x,y,sx,sy : integer;
v : byte;

pData : PChar;
pPixel : PChar;
begin
CurrentBuffer:= ICImagingControl1.ImageActiveBuffer;
CurrentBuffer.Lock();

pData := PChar(CurrentBuffer.ImageDataPtr);

sx := ICImagingControl1.ImageWidth;
sy := ICImagingControl1.ImageHeight;

For x:= 0 to sx - 1 do
For y:= 0 To sy - 1 do
begin
{ read fast from the IC buffer }
pPixel := pData + (x + y * sx) * 3;
ImageA[x,y].r := byte((pPixel + 2)^);
ImageA[x,y].g := byte((pPixel + 1)^);
ImageA[x,y].b := byte((pPixel + 0)^);

{ write back fast to the IC buffer }
byte((pPixel + 2)^) := 255 - ImageA[x,y].r;
byte((pPixel + 1)^) := 255 - ImageA[x,y].g;
byte((pPixel + 0)^) := 255 - ImageA[x,y].b;
end;

ICImagingControl1.DisplayImageBuffer(CurrentBuffer );
CurrentBuffer.Unlock();
end;

brüll
August 2, 2006, 23:02:21
Thanks for the help. Now it is really fast and even convolution works nice. I want to apologize about my harsh remarks. But now sometimes it slows down and freezing occurs, maybe I find a solution by myself. I'm looking forward for solutions of the issues 2. and 3.

Thanks, kind regards.

brüll
August 3, 2006, 00:56:02
Hi, If I use an app with Mr. Vogel's code described above I got some runtime error: BufferTest.exe faulted with Message blabla.

(see attachment). How can i fix it?

Johannes Vogel
August 3, 2006, 08:29:03
Hi,

can you strip down the code to a minimum and post the project in a zip file. Otherwise, I am afraid, I do not have any chance to see what is going wrong.