SetOption Problems

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

SetOption Problems

Post by demonwhisperer »

Hi
I am trying to set the numeric display on my flex c120 camera on with a specific value to reflect the number of tracking object in the cameras views but i am having problems.
I call the following in my code as a test
pCamera->SetOption(NP_OPTION_NUMERIC_DISPLAY_ON, (CComVariant) 2);
....but nothing happens just a message in the log stating "E_INVALIDARG". I know this means the argument is invalid but what should i do to display the number 2 on my Camera's display correctly if this syntax is incorrect? Maybe i'm not fully grasping the Variant concept here...

Thanks for your help in advance.

Regards
Paul Smith
yoshi
Posts: 174
Joined: Sun Jul 24, 2005 5:00 am
Location: silicon valley

Re: SetOption Problems

Post by yoshi »

you can try:
CComVariant var((long)2);
pNPCamera->SetOption(NP_OPTION_NUMERIC_DISPLAY_ON, var);
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: SetOption Problems

Post by demonwhisperer »

Thanks Yoshi but I tried the above and i still can't seem to make a number display on the camera except what automatically display when the camera is run (96 or 99 etc). Am I not including some header files that i should include? Currently these are my included files for my project.

#include "stdafx.h"
#include <conio.h>
#include <objbase.h>
#include <atlbase.h>
#include "optitrack.h"
#import "optitrack.tlb"

Any more suggestions? Thanks

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

Re: SetOption Problems

Post by Birch »

The camera should not be automatically displaying a value on the numeric LED (unless you are using the directshow filter instead of the OptiTrack SDK, in which case they will display "00").

Which version of the OptiTrack SDK are you using and is the camera working properly (tracking) besides the numeric LED?

Here is a change you can make to the VC8b sample which implements what you are interested in doing.

At this function :
void CCameraDlg::UpdateDotInfo(INPCameraFrame * pFrame)
{
LONG lCount = 0;

pFrame->get_Count(&lCount);

Add this in :
// display number of markers found on camera's numeric LED
CComVariant var((long)lCount);
m_spCamera->SetOption(NP_OPTION_NUMERIC_DISPLAY_ON, var);
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: SetOption Problems

Post by demonwhisperer »

The filename for the SDK installer I am using is Optitrack_1.1.030.final.exe. The camera seems to be tracking fine other than the LED problems. I still cannot get your example for displaying the number of markers to work. At the moment There is always 99 displayed on the camera even when I run my code....
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: SetOption Problems

Post by demonwhisperer »

This is the code I'm using in case you can see any obvious problems----->
----------------------------------------------------------

#include "stdafx.h"

#include <atlbase.h>

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

#import "C:\Program Files\NaturalPoint\Optitrack\inc\optitrack.tlb"


INPCameraCollection *cameraCollection;
INPCamera *pCamera;
INPCameraFrame *pFrame;

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

int _tmain(int argc, _TCHAR* argv[])
{
printf("OptiTrack WIN32 Tracking Application ============================================\n");

HRESULT hr;
LONG count;
LONG misc;
LONG waittime;

VARIANT vx[4], vy[4], va[4];

VARIANT voption;

int running = 1;
int toerrors = 0;

printf("Tracking Application Running!\n");

// probably not needed, but doesn't hurt:
for(int i = 0; i < 4; i++)
{
VariantInit(&vx);
VariantInit(&vy);
VariantInit(&va);
}
//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 **) &cameraCollection);

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

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

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

// get one:
hr = cameraCollection->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 = 10; // value in milliseconds; 0 = don't wait; INFINITE = wait till data

running = 1000; // run ~1 minute for waittime=10 ms
//fixed till here
//== Enumerate (Identify) Available Cameras ==========----

//cameraCollection->Enum();

//int frameCounter = 0;

/*
CComPtr<INPCamera> m_spCamera;
CComPtr<INPCameraFrame> m_spFrame;

CComPtr<INPSmoothing> m_spSmoothingDot;
CComPtr<INPSmoothing> m_spSmoothingYaw;
CComPtr<INPSmoothing> m_spSmoothingPitch;
CComPtr<INPSmoothing> m_spSmoothingRoll;
CComPtr<INPSmoothing> m_spSmoothingX;
CComPtr<INPSmoothing> m_spSmoothingY;
CComPtr<INPSmoothing> m_spSmoothingZ;

CComPtr<INPVector> m_spVector;
*/
int ck = 0; //used to display Tracking Now message
LONG lCount = 0;//might not be used
LONG lRank;

INPObject *spObject;

while(running--) {
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;
}


pFrame->get_Count(&lCount);
// display number of markers found on camera's numeric LED
CComVariant var((long)lCount);
pCamera->SetOption(NP_OPTION_NUMERIC_DISPLAY_ON, var);

//start object track
for(int i=0; i<lCount; i++)
{
hr = pFrame->Item(i, &spObject);
HRCHECK("Frame->Item");

hr = spObject->get_Rank(&lRank);
HRCHECK("Object->get_Rank");
if (lRank == 1)
{
if(ck == 0)
printf("Tracking Object(s) Now.\n");

// values are double's so we need to use a variant to query for them
hr = spObject->get_X(&vx[0]);
HRCHECK("Object->get_X");
hr = spObject->get_Y(&vy[0]);
HRCHECK("Object->get_Y");
spObject->get_Area(&va[0]);
HRCHECK("Object->get_Area");
ck = 1;
}
if (lRank == 2)
{

// values are double's so we need to use a variant to query for them
hr = spObject->get_X(&vx[1]);
HRCHECK("Object->get_X");
hr = spObject->get_Y(&vy[1]);
HRCHECK("Object->get_Y");
spObject->get_Area(&va[1]);
HRCHECK("Object->get_Area");
HRCHECK("Object2->get_Area");
}

}
//end object track

//printf("Object 1 Coordinates as follows: \r");
printf("x1 = %.3f, y1 = %.3f Area_1 = %.3f sq. pixels \r", vx[0].dblVal, vy[0].dblVal, va[0].dblVal);

hr = pFrame->Free();
hr = pFrame->Release();

}
pCamera->SetLED(NP_LED_ONE, VARIANT_FALSE);
pCamera->Stop();
pCamera->Close();
pCamera->Release();

}

THANKS

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

Re: SetOption Problems

Post by Birch »

Here is a trimmed version of your code which opens a camera, displays an incrementing value of 1 to 20 and then closes the camera. It has been tested and is working with a C120.

I would also recommend upgrading to the latest version of the OptiTrack SDK - build 31. You can grab it from the download section of the OptiTrack website.

Code: Select all

  
#include "stdafx.h"
#include <atlbase.h>
#include "C:\Program Files\NaturalPoint\Optitrack\inc\optitrack.h"
#import "C:\Program Files\NaturalPoint\Optitrack\inc\optitrack.tlb"

INPCameraCollection *cameraCollection;
INPCamera *pCamera;
INPCameraFrame *pFrame;

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

int _tmain(int argc, _TCHAR* argv[])
{
    printf("OptiTrack WIN32 Tracking Application ============================================\n");

    HRESULT hr;
    LONG count;
    LONG serialnum;
    LONG waittime;

    CoInitialize(NULL); // Startup Microsoft crap

    // create CameraCollection and Vector objects:
    hr = CoCreateInstance(__uuidof(NPCameraCollection), NULL, CLSCTX_ALL, __uuidof(INPCameraCollection), (void **) &cameraCollection);

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

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

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

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

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

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

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

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


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

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

    CComVariant var;

    for (int LEDdisplay = 1; LEDdisplay <= 20; LEDdisplay++)
    {
        var.lVal = LEDdisplay;
        pCamera->SetOption(NP_OPTION_NUMERIC_DISPLAY_ON, var);
        Sleep(100);
    }

    pCamera->SetLED(NP_LED_ONE, VARIANT_FALSE);
    pCamera->Stop();
    pCamera->Close();
    pCamera->Release();
}
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: SetOption Problems

Post by demonwhisperer »

Unfortunatley running this code only seems to display one half a line on the right hand side of the display for a second and then the program terminates. There must be something I'm missing or a setting I have not changed or need to change. I also updated my sdk to the latest one and tested with no differences....
Birch
Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: SetOption Problems

Post by Birch »

If the camera has just been freshly connected to the USB port then does it display the scrolling circular pattern on the numeric LED when the application starts? This should occur the first time the OptiTrack SDK opens a camera after it has been connected to the computer, it should not occur thereafter though.

Also, here is a link to the compiled executable which displays an incrementing counter on the numeric LED.

http://media.naturalpoint.com/software/ ... ED_vc6.zip
demonwhisperer
Posts: 28
Joined: Wed Apr 25, 2007 10:39 am

Re: SetOption Problems

Post by demonwhisperer »

OK. For some reason you compiled executable works fine but when i compile my own code it does nothing. Strange even since my code is the same as yours....

The Output dialog when i build and run the code is as follows: Hope it helps
---------------------------------------------------------

'New Single Track.exe': Loaded 'C:\Program Files\NaturalPoint\Optitrack\samples\Win32Sample\debug\New Single Track.exe', Symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', Symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\lpk.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\usp10.dll', No symbols loaded.
'New Single Track.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\BricoPacks\Vista Inspirat\ObjectDock\DockShellHook.dll', Binary was not built with debug information.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\MSCTF.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\clbcatq.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\comres.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\version.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\Program Files\NaturalPoint\Optitrack\bin\OptiTrack.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\mfc42u.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\msvcp60.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\atl.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\Program Files\NaturalPoint\Optitrack\bin\cameradll.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\mfc42.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\Program Files\NaturalPoint\Optitrack\bin\xerces-c_2_5_0.dll', Binary was not built with debug information.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\avifil32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\msacm32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\msvfw32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\apphelp.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\MSCTFIME.IME', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\wintrust.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\imagehlp.dll', No symbols loaded.
'New Single Track.exe': Loaded 'C:\WINDOWS\system32\xpsp2res.dll', Binary was not built with debug information.
The thread 'Win32 Thread' (0xa78) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x794) has exited with code 35 (0x23).
The thread 'Win32 Thread' (0x374) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xb58) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xc7c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xf70) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xf48) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xfe8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x4ec) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xc78) has exited with code 0 (0x0).
The program '[3144] New Single Track.exe: Native' has exited with code 0 (0x0).
Post Reply