INPVector2

niallm
Posts: 23
Joined: Tue Feb 22, 2005 5:00 am
Location: London Ontario Canada

INPVector2

Post by niallm »

Post from General:
Hi,
I'm developing a program to use multiple cameras to track a single vector clip (multiscreen VR environment). In order to compute the centroid of the clip I need to access the point information provided by the INPPoint and its wrapper. Your sample app does not use this, and I'm a new to the world of C++ .
The SDK document is unclear how to acess the point data.
What exactly is returned by get_Tracking.
If I use the INPVector2->get_Tracking property prior to INPPpoint->get_{X|Y|Z} the program crashes.

Need some guidance.
Thanks
niallm
Posts: 23
Joined: Tue Feb 22, 2005 5:00 am
Location: London Ontario Canada

Re: INPVector2

Post by niallm »

Solved the problem. INPVector2 belongs to INPVector. Might want to revise your docs to reflect the relationship. It doesn't show up in the class diagram at beginning of documentation (page 1-6)

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

Re: INPVector2

Post by Birch »

For those interested, here is a modification to the C++ sample app for interacting with INPVector2 :

Code: Select all

  
(CameraDlg.h)
-----------------------------------
public:
...
    CComPtr<INPVector2> m_spVector;
    CComPtr<INPPoint> m_spPoint;


(CameraDlg.cpp)
-----------------------------------
BOOL CCameraDlg::OnInitDialog()
...
    m_spVector.CoCreateInstance(CLSID_NPVector);
    m_spPoint.CoCreateInstance(CLSID_NPPoint);


void CCameraDlg::UpdateVectorInfo(INPCameraFrame * pFrame)
...
   CComVariant varYaw, varPitch, varRoll, varX, varY, varZ, varEmpty;

   // Process the vector data
   m_spVector->Update(m_spCamera, pFrame);

   m_spVector->get_Yaw(&varYaw);
   m_spVector->get_Pitch(&varPitch);
   m_spVector->get_Roll(&varRoll);

   // Get Point number 0 on the clip
   m_spVector->GetPoint(0, &m_spPoint);

   m_spPoint->get_X(&varX);
   m_spPoint->get_Y(&varY);
   m_spPoint->get_Z(&varZ);

   // important to free this
   m_spPoint.Release();
macdrevx
Posts: 1
Joined: Mon Jun 09, 2008 8:17 am

Re: INPVector2

Post by macdrevx »

A year and a half later, this has been very helpful. Thanks!

Is there a better way to get position data than from INPVector? I'm using the OptiTrack SDK.
Birch
Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: INPVector2

Post by Birch »

The next step up is out Point Cloud and Rigid Body toolkits. They provide much more powerful tracking and full SDKs, but also require a license to be purchased.
Mark Scopes
Posts: 5
Joined: Tue Nov 04, 2008 7:50 am

Re: INPVector2

Post by Mark Scopes »

Is the a C not C++ sample app for this I just want to start wit a sigle camera and return the vector information.
Birch
Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: INPVector2

Post by Birch »

We haven't got any plain C code, though you might be able to use the C++ code as a reference for interfacing with it using plain C.
Mark Scopes
Posts: 5
Joined: Tue Nov 04, 2008 7:50 am

Re: INPVector2

Post by Mark Scopes »

I am trying to write a small demonstration program to covert head moment to PTZ camera control.

It was suggested that the OptiTrack SDK would be a good place to start. I am using version 1.81 with a TrackIR camera. I am writing the program in "C" not "C++" using National Instruments CVI.

I have included the code and having the following problems:
1/ I was expecting the command
hr = INPCamera_GetFrame(camera,waittime,&frame);
to give me a value into the frame variable, although hr returns 0.

2/The command line
hr = INPVector_Update(vector, camera, frame);
Gives me a general protection fault at 001B:011DFD71.

I expect I am missing something with the TrackIR in terms of some code. Can you help ???



#define COBJMACROS

#include
//#include
#include "d:\Programs\Track\optitrack.h"
#include
#include

char panhndl,buff[128];
int n,p=1;

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, 0, 0) == 0) /* needed if linking DLL in external compiler; harmless otherwise */
return (-1); /* out of memory */

panhndl = LoadPanel (0, "track test.uir", 1);
n = DisplayPanel (panhndl);
RunUserInterface ();


return 0;
}

int CVICALLBACK stop(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
switch (event) {
case EVENT_COMMIT:
/* Close UIR */
p = 1;
n = DiscardPanel (panhndl);
QuitUserInterface (0);
/* End */

break;
}
return 0;
}

int CVICALLBACK Start(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{


INPCameraCollection *collection = NULL;
INPCamera *camera = NULL;
INPCameraFrame *frame = NULL;
INPVector *vector = NULL;
HRESULT hr;
VARIANT vx, vy,vz, vyaw, vpitch, vroll;
VARIANT voption;

long cameraCount, camera_sn, waittime = INFINITE, camera_model;


n = SetCtrlAttribute (panhndl, 2, ATTR_DIMMED, 0);
n = SetCtrlAttribute (panhndl, 3, ATTR_DIMMED, 1);

/* Create cameraCollection and Vector objects */
CoInitialize(NULL);
hr = CoCreateInstance(&CLSID_NPCameraCollection, NULL, CLSCTX_ALL, &IID_INPCameraCollection, (void **)&collection);
hr = CoCreateInstance(&CLSID_NPVector, NULL, CLSCTX_ALL, &IID_INPVector, (void **)&vector);


/* Find all cameras */
INPCameraCollection_Enum(collection);
ProcessSystemEvents ();
INPCameraCollection_get_Count(collection, &cameraCount);
ProcessSystemEvents ();
/* Print bit */
n=Fmt(buff,"%s<%s%d","Camra count = ",cameraCount);
n = InsertTextBoxLine (panhndl, 4, 0, buff);
ProcessSystemEvents ();

/* First identifier of camera select camera*/
hr = INPCameraCollection_Item(collection, 0, &camera);

hr = INPCamera_get_SerialNumber(camera, &camera_sn);
/* Print bit */
n=Fmt(buff,"%s<%s%d","Camera SN = ",camera_sn);
n = InsertTextBoxLine (panhndl, 4, 0, buff);
ProcessSystemEvents ();

hr = INPCamera_get_Model(camera, &camera_sn);
/* Print bit */
n=Fmt(buff,"%s<%s%d","Camera Model = ",camera_model);
n = InsertTextBoxLine (panhndl, 4, 0, buff);
ProcessSystemEvents ();

ProcessSystemEvents ();

hr = INPCamera_Open(camera);
hr = INPCamera_SetLED(camera, NP_LED_ONE, VARIANT_TRUE);
if(hr == 0)
{
hr = INPCamera_SetOption(camera, NP_OPTION_SEND_EMPTY_FRAMES, voption);
}
hr = INPCamera_Start(camera);

hr = INPVector_Reset(vector);

while (p == 1)
{
hr = INPCamera_GetFrame(camera,waittime,&frame);
if (FAILED(hr))
{
switch(hr)
{
case S_OK:
n = InsertTextBoxLine (panhndl, 4, 0,"OK\n");
break;
case E_POINTER:
n = InsertTextBoxLine (panhndl, 4, 0,"E_POINTER\n");
break;
case NP_E_DEVICE_DISCONNECTED:
n = InsertTextBoxLine (panhndl, 4, 0,"NP_E_DEVICE_DISCONNECTED\n");
break;
case NP_E_DEVICE_NOT_SUPPORTED:
n = InsertTextBoxLine (panhndl, 4, 0,"NP_E_DEVICE_NOT_SUPPORTED\n");
break;
case HRESULT_FROM_WIN32(ERROR_TIMEOUT):
n = InsertTextBoxLine (panhndl, 4, 0,"HRESULT_FROM_WIN32(ERROR_TIMEOUT)\n");
break;
default:
n = InsertTextBoxLine (panhndl, 4, 0,"default\n");
break;
}
continue;
}

hr = INPVector_Update(vector, camera, frame);

hr = INPVector_get_X(vector, &vx);
hr = INPVector_get_X(vector, &vy);
hr = INPVector_get_X(vector, &vz);
hr = INPVector_get_Yaw(vector, &vyaw);
hr = INPVector_get_Pitch(vector, &vpitch);
hr = INPVector_get_Roll(vector, &vroll);

hr = INPCameraFrame_Free(frame);

/* Print bit */
//n=Fmt(buff,"%s<%s","hello ");
ProcessSystemEvents ();



Beep;
hr = INPCamera_Close(camera);
}

return(0);

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

Re: INPVector2

Post by Birch »

[quote=Mark_Scopes]

I have included the code and having the following problems:
1/ I was expecting the command
hr = INPCamera_GetFrame(camera,waittime,&frame);
to give me a value into the frame variable, although hr returns 0.

2/The command line
hr = INPVector_Update(vector, camera, frame);
Gives me a general protection fault at 001B:011DFD71.

I expect I am missing something with the TrackIR in terms of some code. Can you help ???

[/quote]

One thing is to make sure the returned frame is not NULL before trying to pass it to INPVector, this has been covered other in other topics in the forum. A success return code from GetFrame() does not guarantee that the frame returned is valid, you still need to check it. You may want to call GetFrame() multiple times until it returns a usable frame.
Mark Scopes
Posts: 5
Joined: Tue Nov 04, 2008 7:50 am

Re: INPVector2

Post by Mark Scopes »

I have writen a loop as suggested, the below line always returns null.
hr = INPCamera_GetFrame(camera,waittime,&frame);


I beleve the problem is before this as the start line
hr = INPCamera_Start(camera); returns -2147467259 is this due to the hardware type a TrackIR ?

I can obtain the cameras model number of 268959914 and serial number of 64965 using the
hr = INPCamera_get_Model(camera, &camera_model);
and
hr = INPCamera_get_SerialNumber(camera, &camera_sn);
so I am in comunication with the camera.
Post Reply