C++ Single dot tracking Problem

demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

C++ Single dot tracking Problem

Post by demonwhisperer »

Hi I just purchased an Optitrack camera recently and am having some problem with single dot tracking. I can get the camera to track a single dot using the sample c++ win32 app but the camera does not register the dot until it is about a 1/2 foot away from the camera. I assume this is something to do with a setting for the max size of the tracking object but I am having trouble using SetOption to change parameters such as NP_OPTION_OBJECT_MASS_MAX and NP_OPTION_OBJECT_MASS_IDEAL. Maybe I am on the wrong track here. Could you please provide me with some sample code demonstrating this and point me in the right direction. Thanks very much in advance.

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

Re: C++ Single dot tracking Problem

Post by Birch »

The cameras should be able to track objects of most sizes from the outset without tuning. There are a couple details that might help determine what the issue is :
  • What model is the camera (FLEX:C120, FLEX:V100, SLIM:V100)? (and serial number as well if possible)
  • Can you post a screenshot of what the sample app shows when the dot just begins to track?
  • What is the object/marker that you are tracking made of?
  • What are the settings for the Exposure, Threshold and LED Intensity?
  • If you switch the camera to grayscale mode, is the image in focus?
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: C++ Single dot tracking Problem

Post by demonwhisperer »

Its a Flex:C120. Serial is 056108 I think. The object marker is just a 1/3 inch reflective dot sticker i purchased with the camera. The exposure, threshold and LED intensity should be default since i have not changed them since i recieved the camera.

I am not sure what you mean by switching the camera to grayscale mode. Is there a setting in the OptiCapture app for that? Heres a screenshot as you requested:

[image]http://www.compsoc.nuigalway.ie/~paulsmith/track.jpg[/image]

Cheers
Paul
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: C++ Single dot tracking Problem

Post by demonwhisperer »

When I view the camera in the OptiCapture app it seems in focus. Any help would be greatly appreciated thanks.
Birch
Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: C++ Single dot tracking Problem

Post by Birch »

I am not sure what you mean by switching the camera to grayscale mode. Is there a setting in the OptiCapture app for that?
There are two sample applications from our download section which can be used to switch between grayscale and thresholded modes in the camera. You can use either the "C++ VC8/2005 Sample" or the "C# VC8/2005 .NET 3.0 Sample". If you could post the screenshot of both the grayscale and thresholded mode images, that would be helpful.

http://www.naturalpoint.com/optitrack/s ... tions.html
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: C++ Single dot tracking Problem

Post by demonwhisperer »

heres a screenshot of grayscale mode:

[image]http://compsoc.nuigalway.ie/~paulsmith/gray.jpg[/image]

Thanks
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: C++ Single dot tracking Problem

Post by demonwhisperer »

This is the code i'm compiling: Please take a look, thanks

--------------------------------------------------------
#include "stdafx.h"

#include "C:\Program Files\NaturalPoint\Optitrack\inc\optitrack.h"

INPCameraCollection *pCameraCollection;
INPCamera *pCamera;
INPCameraFrame *pFrame;
INPVector *pVector;


#define HRCHECK(message) if (FAILED(hr)) { fprintf(stderr, "%s\n", message); return 0; }

int main(int argc, char* argv[])
{
HRESULT hr;
LONG count;
LONG misc;
LONG waittime;

VARIANT vx, vy, vz;
VARIANT vyaw, vpitch, vroll;
VARIANT voption;
//VARIANT *val;

//VariantInit(val);
//VARIANT v;
//val[0].vt = VT_R8;
//v = 20.0;
//val = &v;
int running = 1;
int toerrors = 0;

printf("Single Point Tracking Test!\n");

// probably not needed, but doesn't hurt:
VariantInit(&vx);
VariantInit(&vy);
VariantInit(&vz);
VariantInit(&vyaw);
VariantInit(&vpitch);
VariantInit(&vroll);
VariantInit(&voption);

CoInitialize(NULL); // Startup Microsoft crap

// create CameraCollection and Vector objects:

hr = CoCreateInstance(__uuidof(NPCameraCollection), NULL, CLSCTX_ALL,
__uuidof(INPCameraCollection), (void **) &pCameraCollection);
HRCHECK("CoCreateInstance for CameraCollection");

hr = CoCreateInstance(__uuidof(NPVector), NULL, CLSCTX_ALL,
__uuidof(INPVector), (void **) &pVector);
HRCHECK("CoCreateInstance for Vector");

// find all the cameras:
hr = pCameraCollection->Enum();
HRCHECK("CameraCollection->Enum");

hr = pCameraCollection->get_Count(&count);
HRCHECK("CameraCollection->get_Count");

if (count < 1) {
fprintf(stderr, "camera count < 1\n");
return 0;
}

// get one:
hr = pCameraCollection->Item(0, &pCamera);
HRCHECK("CameraCollection->Item");

hr = pCamera->get_SerialNumber(&misc);
HRCHECK("Camera->get_SerialNumber");

printf("serial number = %ld\n", misc);

hr = pCamera->Open();
HRCHECK("Camera->Open");

// turn on illumination LEDs
hr = pCamera->SetLED(NP_LED_ONE, VARIANT_TRUE);
HRCHECK("Camera->SetLED");

#if 0
voption.vt = VT_BOOL;
voption.boolVal = VARIANT_TRUE;
hr = pCamera->SetOption(NP_OPTION_SEND_EMPTY_FRAMES, voption);
HRCHECK("Camera->SetOption");
#endif

hr = pCamera->Start();
HRCHECK("Camera->Start");

waittime = 100; // value in milliseconds; 0 = don't wait; INFINITE = wait till data

pVector->Reset();
HRCHECK("Vector->Reset");

running = 60000; // run ~1 minute for waittime=10 ms

//INPCamera::SetOption(NP_OPTION_OBJECT_MASS_IDEAL, val);

while(running--) {//runs for 6000ms ie. 1 minute

hr = pCamera->GetFrame(waittime, &pFrame);

if (FAILED(hr)) {
// fprintf(stderr,"Camera->GetFrame %x ", hr);
switch(hr) {
case S_OK:
fprintf(stderr, "OK\n"); break;
case E_POINTER:
fprintf(stderr, "E_POINTER\n"); break;
case NP_E_DEVICE_DISCONNECTED:
fprintf(stderr, "NP_E_DEVICE_DISCONNECTED\n"); break;
case NP_E_DEVICE_NOT_SUPPORTED:
fprintf(stderr, "NP_E_DEVICE_NOT_SUPPORTED\n"); break;
case HRESULT_FROM_WIN32(ERROR_TIMEOUT):
/*fprintf(stderr, "HRESULT_FROM_WIN32(ERROR_TIMEOUT)\n");*/
toerrors++;
break;
default:
fprintf(stderr, "default\n"); break;
}
continue;
}

hr = pVector->Update(pCamera, pFrame);
HRCHECK("Vector->Update");

hr = pVector->get_X(&vx);
HRCHECK("Vector->get_X");

hr = pVector->get_Y(&vy);
HRCHECK("Vector->get_Y");

hr = pVector->get_Z(&vz);
HRCHECK("Vector->get_Z");

hr = pVector->get_Yaw(&vyaw);
HRCHECK("Vector->get_Yaw");

hr = pVector->get_Pitch(&vpitch);
HRCHECK("Vector->get_Pitch");

hr = pVector->get_Roll(&vroll);
HRCHECK("Vector->get_Roll");

printf("x=%.3f y=%.3f z=%.3f yaw=%.3f pitch=%.3f roll=%.3f \r",
vx.dblVal, vy.dblVal, vz.dblVal, vyaw.dblVal, vpitch.dblVal, vroll.dblVal);

hr = pFrame->Free();

}

printf("\n\n%d timeouts\n", toerrors);

printf("\nFin\n");

// shut everything down
pCamera->SetLED(NP_LED_ONE, VARIANT_FALSE);
pCamera->Stop();
pCamera->Close();

CoUninitialize();

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

Re: C++ Single dot tracking Problem

Post by Birch »

heres a screenshot of grayscale mode:
(grayscale image)

Thanks
Is this that scene that you are trying to track? If not, could you post an image of what you are trying to track?
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: C++ Single dot tracking Problem

Post by demonwhisperer »

This is the scene i am attempting to track, it is just a simple tracking sticker on the end of a pencil. The application for changing the options of the camera manages to track it without any problem, but the code i'm using is using vectors and doesn't seem to work.

[image]http://www.compsoc.nuigalway.ie/~paulsmith/track2.jpg[/image]

Thanks
Paul
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: C++ Single dot tracking Problem

Post by demonwhisperer »

I believe the reason my object won't track is because my code is using INPVector instead of INPObject. Would it be possible for you to give me a simple code example of a win32 app to track using INPObject instead of INPVector? I just need to know the steps needed to set the system up and initilise everything for tracking. I would very much appreciate your input. Thanks

Paul
Post Reply