Sample code (delphi, C#)

danzman
Posts: 13
Joined: Thu Dec 22, 2005 5:00 am
Location: Orland Park, Illinois

Sample code (delphi, C#)

Post by danzman » Thu Dec 22, 2005 7:24 am

Anyone out there have a starting code written in object pascal (delphi)?

[ April 13, 2006, 11:50 AM: Message edited by: NaturalPoint - Birch Zimmer ]

danzman
Posts: 13
Joined: Thu Dec 22, 2005 5:00 am
Location: Orland Park, Illinois

Re: Sample code (delphi, C#)

Post by danzman » Thu Dec 29, 2005 8:05 am

I got a message to join the group that works with Delphi but have not seen anyone discussing Delphi applications. Can the tech guys from NP give us a clue on how to use the SDK?

AnarchyRising
Posts: 2
Joined: Mon Jan 09, 2006 5:00 am
Location: PA, USA

Re: Sample code (delphi, C#)

Post by AnarchyRising » Sun Jan 08, 2006 11:30 pm

Hopefully some Delphi support is offered up. I just got 3 Opti's and am a seasoned Delphi coder. Although COM is not a strong point of mine because I never needed to use it before, hopefully subject to change soon.

Birch
Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: Sample code (delphi, C#)

Post by Birch » Wed Jan 11, 2006 9:26 am

We do not currently supply OptiTrack sample applications in the Delphi language with the SDK, and unfortunately we do not have current plans to develop them in-house.

We recommend reviewing the product manual that is included when the OptiTrack SDK is installed, along with the C++, Visual Basic and VB script examples which help demonstrate the basic method for implementing and interacting with the OptiTrack SDK and cameras (which functions to call and for what reasons).

We are aware that some users have developed Delphi applications which use the OptiTrack SDK and would welcome any sample code which those users might consider sharing with others.

[ January 11, 2006, 04:28 PM: Message edited by: NaturalPoint - Birch Zimmer ]

danzman
Posts: 13
Joined: Thu Dec 22, 2005 5:00 am
Location: Orland Park, Illinois

Re: Sample code (delphi, C#)

Post by danzman » Thu Jan 12, 2006 3:25 am

OK. I guess I have to sweat it out. Here is what I did so far in Delphi Win32 app. The project mainform has 3 controls as starter: Edit box, and 2 labels (X and Y). The NPCameraCollection, NPCamera, NPSmoothing, NPVector components were dropped into the form.

(I am not a VB expert but I tried to translate the sample code to Delphi the best I can.)

OnCreate event of the form this is the code:

************************************
procedure TForm2.FormCreate(Sender: TObject);
begin
FrameCount:=0; //** declared in the public section as type integer
TheCameras.Enum; //** TNPCameraCollection
Edit1.Text:=IntToStr(TheCameras.Count);
Camera.ConnectTo(TheCameras.Item(0)); //** TNPCamera
Camera.Open;
Camera.Start;
end;
**********************************

The procedure succesfully fired the camera (Hurray!)
Now we need to capture the data from the camera (Here is where I got stuck and need help from the gurus out there):

On the CameraFrameAvailable event of the NPCAmera I placed the following code:

*************************

procedure TForm2.CameraFrameAvailable(ASender: TObject;
const pCamera: INPCamera);
var oNewFrame:INPCameraFrame;
begin
// if frame is available
try

oNewFrame:= Camera.GetFrame(0);
Inc(FrameCount);

NPVector1.Update(pCamera, oNewFrame); //** THIS CREATED A FLOATING POINT EXCEPTION!

// *** these vars were predeclared as type NPSmoothing
oNPSmootherX.Update(NPVector1.X,0);
oNPSmootherY.Update(NPVector1.Y,0);

If (FrameCount)>4 then begin
FrameCount:=0;
LabelX.Caption:='X:'+FormatFloat('###0.000',oNPSmootherX.X);
LabelY.Caption:='Y:'+FormatFloat('###0.000',oNPSmootherY.Y);
end;

oNewFrame:=nil;
except
// if there is an exception, make sure we do not leave the camera on!
Camera.Stop;
Camera.Close;
end; // try
end;

*************************
For my project I just the need the data that will show me the lateral motion of the object being tracked (at least for now). Any ideas out there?

Birch
Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: Sample code (delphi, C#)

Post by Birch » Fri Jan 13, 2006 6:54 am

Dave Mills, one of our OptiTrack beta testers, has generously provided a Delphi sample application which demonstrates basic interaction with a camera.

We hope this proves useful.

To start video, use the following sequence :
1) Device Collection Enum
2) My Camera Open
3) My Camera Start
4) Start Timer

(disclaimer)
The sample provided is not an official software release or product of NaturalPoint and we do not guarantee support or assume liability that might result from its use.

http://media.naturalpoint.com/files/Del ... icTest.zip

[ January 13, 2006, 02:00 PM: Message edited by: NaturalPoint - Birch Zimmer ]

danzman
Posts: 13
Joined: Thu Dec 22, 2005 5:00 am
Location: Orland Park, Illinois

Re: Sample code (delphi, C#)

Post by danzman » Thu Jan 19, 2006 12:45 pm

My gratitude to Dave for the code. I will give it a whirl first thing tomorrow.

This is the edited post - I could not wait for tomorrow. I tried compiling the program but I got an error saying that NPCameraCollection.OnDeviceArrival and OnDeviceRemoval has invalid parameter list.

Can you tell us which version of Delphi and SDK were used?

[ January 19, 2006, 09:27 PM: Message edited by: danzman ]

danzman
Posts: 13
Joined: Thu Dec 22, 2005 5:00 am
Location: Orland Park, Illinois

Re: Sample code (delphi, C#)

Post by danzman » Sat Jan 21, 2006 5:26 pm

Using Delphi2005 I managed to make the program work. It still gave me the parameter-list error and when ask during compilation I chose not to ignore but selected the option "No" meaning, to go ahead and compile.

I got the the data that I need generated (x,y coordinates of the object). There are some issues I need to work on but in the meantime this is getting closer to my goal. Again, Dave thanks for the starting code. I will try to find out what generates the compiler error.

Birch
Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: Sample code (delphi, C#)

Post by Birch » Thu Apr 13, 2006 4:55 am

also see this thread for a c++ example

dean
Posts: 6
Joined: Thu Jan 12, 2006 5:00 am
Location: Corvallis, OR
Contact:

Re: Sample code (delphi, C#)

Post by dean » Thu Apr 13, 2006 7:00 am

A C# Starter application is now available for download.
Source

Post Reply