Problem getting a frame from the device

Post Reply
Franck
Posts: 2
Joined: Wed Sep 05, 2007 2:06 pm

Problem getting a frame from the device

Post by Franck »

I'm using a TrackIR4 hardware with the OptiTrack Sdk.

I succesfully initialize my camera but in the update code of my application, I call the GetFrame function, but don't seem to receive nothing from the function which return a S_Ok code.

hr = m_pCamera->GetFrame(waittime, &m_pFrame);

The application crash when I try to update my vector with the collected frame.

hr = m_pVector->Update(m_pCamera, m_pFrame);

Here is my initialization code:
LONG count;
LONG misc;

printf("Hello World!\n");

// probably not needed, but doesn't hurt:
VariantInit(&m_vX);
VariantInit(&m_vY);
VariantInit(&m_vZ);
VariantInit(&m_vYaw);
VariantInit(&m_vPitch);
VariantInit(&m_vRoll);
VariantInit(&m_vOption);

CoInitialize(NULL); // Startup Microsoft crap

// create CameraCollection and Vector objects:

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

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

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

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

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

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

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

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

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

//turn on illumination LEDs
hr = m_pCamera->SetLED(NP_LED_ONE, VARIANT_TRUE);
HRCHECK("Camera->SetLED");
//hr = m_pCamera->SetLED(NP_LED_TWO, VARIANT_TRUE);
hr = m_pCamera->SetLED(NP_LED_TWO, VARIANT_FALSE);
//HRCHECK("Camera->SetLED");
//hr = m_pCamera->SetLED(NP_LED_THREE, VARIANT_TRUE);
hr = m_pCamera->SetLED(NP_LED_THREE, VARIANT_FALSE);
//HRCHECK("Camera->SetLED");
//hr = m_pCamera->SetLED(NP_LED_FOUR, VARIANT_TRUE);
hr = m_pCamera->SetLED(NP_LED_FOUR, VARIANT_FALSE);
//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 = m_pCamera->Start();
HRCHECK("Camera->Start");

m_pVector->Reset();
HRCHECK("Vector->Reset");
My header file has those members:
INPCameraCollection *m_pCameraCollection;
INPCamera *m_pCamera;
INPCameraFrame *m_pFrame;
INPVector *m_pVector;

VARIANT m_vX, m_vY, m_vZ;
VARIANT m_vYaw, m_vPitch, m_vRoll;
VARIANT m_vOption;
Thanks
Franck
Posts: 2
Joined: Wed Sep 05, 2007 2:06 pm

Re: Problem getting a frame from the device

Post by Franck »

Found the answer on another thread.

Putting a Sleep(1) before getting a new frame correct the problem.
Post Reply