Page 1 of 2

Sample code (delphi, C#)

Posted: Thu Dec 22, 2005 7:24 am
by danzman
Anyone out there have a starting code written in object pascal (delphi)?

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

Re: Sample code (delphi, C#)

Posted: Thu Dec 29, 2005 8:05 am
by danzman
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?

Re: Sample code (delphi, C#)

Posted: Sun Jan 08, 2006 11:30 pm
by AnarchyRising
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.

Re: Sample code (delphi, C#)

Posted: Wed Jan 11, 2006 9:26 am
by Birch
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 ]

Re: Sample code (delphi, C#)

Posted: Thu Jan 12, 2006 3:25 am
by danzman
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);
FrameCount:=0; //** declared in the public section as type integer
TheCameras.Enum; //** TNPCameraCollection
Camera.ConnectTo(TheCameras.Item(0)); //** TNPCamera

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;
// if frame is available

oNewFrame:= Camera.GetFrame(0);

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

// *** these vars were predeclared as type NPSmoothing

If (FrameCount)>4 then begin

// if there is an exception, make sure we do not leave the camera on!
end; // try

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?

Re: Sample code (delphi, C#)

Posted: Fri Jan 13, 2006 6:54 am
by Birch
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

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

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

Re: Sample code (delphi, C#)

Posted: Thu Jan 19, 2006 12:45 pm
by danzman
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 ]

Re: Sample code (delphi, C#)

Posted: Sat Jan 21, 2006 5:26 pm
by danzman
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.

Re: Sample code (delphi, C#)

Posted: Thu Apr 13, 2006 4:55 am
by Birch
also see this thread for a c++ example

Re: Sample code (delphi, C#)

Posted: Thu Apr 13, 2006 7:00 am
by dean
A C# Starter application is now available for download.