Page 1 of 1

INPSmoothing Interface

Posted: Thu Jun 05, 2008 6:20 am
by Queeny
Hello,

I am trying to acheive single point tracking using the optitrack system and C++. I am using the samples to understand how to use the interfaces.

I am having problems with the Update method of the smoothing interface.
The program compiles, but I get an error during run time when smoothing->update is reached.

I need help on what may be the problem, because I do not see it.

Here is some of my code:



int _tmain(int argc, _TCHAR* argv[])
{

//== Initialize Microsoft COM Interop ================----
CoInitialize(NULL);

//== Initialize OptiTrack COM Component ==============----
CComPtr cameraCollection; //1 Create the INPCamera Collection object
CComPtr camera;
CComPtr frame;

cameraCollection.CoCreateInstance(CLSID_NPCameraCollection);

//== Enumerate (Identify) Available Cameras ==========----
cameraCollection->Enum();//2 Call the Enum() method to enumerate the devices in the system

long cameraCount = 0;
int frameCounter = 0;



//== Determine Available Cameras =====================----
cameraCollection->get_Count(&cameraCount); //3 walk the list of cameras in the collection

printf("%d Camera(s) Detected:\n\n", cameraCount);

if (cameraCount>0)
{




unsigned char frameBuffer[353*288];

cameraCollection->Item(0, &camera); //returns the camera interface
{
camera->Open();// 4a Call the Open() method in INPCamera
camera->Start();//4e Starts collection of frame information from the camera
{
while(!_kbhit())//= run what is in this loop until a key is pressed
//_kbhit notes if you have pressed a key...
{

Sleep(5); //wait 5 ms before doing next line of code
//"The Sleep function suspends the execution of the current thread for a specified interval."



MSG msg;
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if(GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}


//return most recent frame from the camera
camera->GetFrame(0, &frame);//0=to not block thread
//!0= amount of time in ms to wait for a frame
//INFINITE= causes thread to wait indefinitely


if(frame!=0) //if a frame was returned
{

//== New Frame Has Arrived ==========================------
frameCounter++;

if(frameCounter%30==0)
{


camera->GetFrameImage(frame, 353, 288, 353, 8, (byte *) &frameBuffer);


LONG objectCount=0;
frame->get_Count (&objectCount);

cout object; //create an object instance
frame->Item(i, &object); //get object in frame
LONG Rank;
object->get_Rank(&Rank); //get the rank of this object

if(Rank==1) //if this is the tracked object...
{
CComVariant X, Y, Area;
CComPtr SmoothingDot;

//get data: (x,y) and Area
object->get_X (&X);
object->get_Y (&Y);
object->get_Area(&Area);


//Smooth data

SmoothingDot->Update (X, Y; //here is where my error occurs
SmoothingDot->get_X (&X); //get smoothed data
SmoothingDot->get_Y (&Y);

}

object.Release();


}
frame->Free();
frame.Release();
}
}
}
camera->Stop();
camera->Close();
}

camera.Release();
}


//== Always Clean-up COM Objects ================----
cameraCollection.Release();

//== Uninitialize Microsoft COM Interop =============----
CoUninitialize();

printf("Application Exit.\n");
getchar();
return 0;
}

Re: INPSmoothing Interface

Posted: Fri Jun 06, 2008 2:35 pm
by Birch
In order for the smoothing object to be effective, it needs to build up a history of location data over several frames. This means having the object persist for more than one frame. Try declaring it in the same location as the CameraCollection. It should also have CoCreateInstance() called on it.

// declare
CComPtr SmoothingDot;

// init
SmoothingDot.CoCreateInstance(CLSID_NPSmoothing);
SmoothingDot->Reset();