null frames

symfonysid
Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

null frames

Post by symfonysid »

Hi,
symfonysid
Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

Re: null frames

Post by symfonysid »

Oops...

Hi,

I've been trying to use the Optitrack V100 at its highest frame rate of 100 frames. In my own application I noticed that when I did this that suddenly I was getting a lot of null frames interspersed with the good frames. The camera was configured to send no null frames, and of course the fact that it was sending random null frames interfered with my tracking of objects, because when I received a null frame, I assumed that meant the tracked object had disappeared.

I modified Optitrack's own sample command line application to see if the problem also occurs there, and it did. I'm going to upload it below... Can you suggest anything to suppress these null frames while running the camera at this frame rate?

Best,
Greg


//========================================================================-----
//== OptiTrack WIN32 Sample Application
//== Copyright 20067 NaturalPoint
//==
//== This sample is intended to show how to properly access and control
//== OptiTrack cameras. The application does the following:
//==
//== 1. Initializes the OptiTrack COM Component.
//== 2. Displays information about all connected cameras.
//== 3. Starts the first camera in the system and displays ongoing info.
//== 4. Unintializes the OptiTrack cameras, COM, and terminates.

//== INCLUDES ============================================================-----

#include "stdafx.h"
#include //== For sample simplicity: kbhit()

//== NECESSARY OPTITRACK INCLUDES AND DEFINITIONS ========================-----

#include "Timer.h"

#include
#include
#include "optitrack.h"
#import "optitrack.tlb"
//== SAMPLE APPLICATION ENTRY POINT ======================================-----

int _tmain(int argc, _TCHAR* argv[])
{
printf("OptiTrack WIN32 Sample Application ============================================\n");
printf("Copyright 2007 NaturalPoint =============================================------\n\n");

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

//== Initialize OptiTrack COM Component ==============----
CComPtr cameraCollection;
CComPtr camera;
CComPtr frame;

cameraCollection.CoCreateInstance(CLSID_NPCameraCollection);

//== Enumerate (Identify) Available Cameras ==========----
cameraCollection->Enum();

long cameraCount = 0;
int frameCounter = 0;

//== Determine Available Cameras =====================----
cameraCollection->get_Count(&cameraCount);

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

//== Display Camera Information for All Cameras ======----
for(int index=0; indexItem(index, &camera);

long serial,width,height,model,revision,rate;

camera->get_SerialNumber(&serial);
camera->get_Width (&width);
camera->get_Height (&height);
camera->get_Model (&model);
camera->get_Revision (&revision);
camera->get_FrameRate (&rate);

printf(" Camera %d\n",serial);
printf(" =========================\n");
printf(" Resolution: %dx%d\n",width,height);
printf(" Revision : 0x%8x\n",revision);
printf(" Model : 0x%8x\n",model);
printf(" Frame rate: %d\n\n" ,rate);

//== Set Some Camera Options ====================----

//== Set Greyscale Mode =========================----
camera->SetOption(NP_OPTION_VIDEO_TYPE , (CComVariant) 2 );

//== Set to discard every other frame ===========----
//== 60 Frames/Second on the C120 ===============----
camera->SetOption(NP_OPTION_FRAME_DECIMATION , (CComVariant) 0 );

camera->SetOption(NP_OPTION_THRESHOLD, (CComVariant) 100);

//camera->SetOption(NP_OPTION_SEND_EMPTY_FRAMES, (CComVariant) false);

//== Display 99 on the Camera ===================----
//== Note: This only works for cameras with a display
camera->SetOption(NP_OPTION_NUMERIC_DISPLAY_ON, (CComVariant) 99);

camera->SetOption(NP_OPTION_FRAME_RATE, (CComVariant) 100);

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

//== Open the first camera ==========================----

if(cameraCount>0)
{
//== Allocate Camera Greyscale Image Memory ========================-----
unsigned char frameBuffer[353*288];

printf("\nPress Return To Exit\n\n");
printf("Average brightness calculation returns 0.0 for cameras that do not\n");
printf("support grayscale images. (Grayscale only available in OptiTrack FLEX:C120 cameras)\n");

cameraCollection->Item(0, &camera);
{
camera->Open();
camera->Start();
Timer theTimer;
theTimer.start();
{
while(!_kbhit())
{
Sleep(5);

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

camera->GetFrame(INFINITE, &frame);

if(frame==0)
{
std::cout 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;
}
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: null frames

Post by beckdo »

What is it that you're trying to do? You're calling GetFrame() at a higher rate then 100FPS so you'll likely get lots of NULLs frames.
symfonysid
Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

Re: null frames

Post by symfonysid »

Hi,

I'm tracking blobs of infrared light with a single camera on a surface...

I am calling GetFrame() at a higher rate than 100 FPS, but I'm calling it with the argument to wait infinitely for the next frame to arrive. It would be alright if it was returning a null frame, because no blobs were detected, but it's returning null frames when there are actually blobs there which as I explained before is messing up my blob tracking.

If I sleep for 10 milliseconds before calling this method, then I only get a frame rate of 85 FPS. If I sleep for 9 milliseconds, then I get about 100 FPS. But the optimal sleep time really depends on how much work the application is doing (is it or isn't diplaying the images?) and what kind of computer it is running on. So, changing the sleep time isn't a good way to deal with this problem. If I call GetFrame() with the argument to wait infinitely, it should give me 100 null frames per second if there are no objects there, or if there are object there, it should give me 100 good frames. But if there are objects there, it shouldn't be giving me 100 good frames with a bunch of random null frames interspersed in the mix.

Greg
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: null frames

Post by beckdo »

Hey Greg,

You might want to measure the frame rate coming out of the sample applications just to confirm you're getting 100 FPS. Something else you should know is that GetFrame() does not return NULL for empty frames. It won't return anything unless you use SetOption() to set the send frame options to send all frames.

D
symfonysid
Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

Re: null frames

Post by symfonysid »

Hi Doug,

Okay, thanks for the tips. I misunderstood what the setOption for empty frames meant. I thought that if this was false then calling getFrame() would block until a frame arrived which I didn't want, but that's not the case...

Everything is working fine with the camera now, but I think in the future I'd like to switch to using a callback rather than calling GetFrame(). I've looked through the posted examples, and I didn't see any example of how to use a callback with C++. Do you know where I might be able to find one?

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

Re: null frames

Post by Birch »

The C++ VC8/2005 sample (VC8b) uses the FrameAvailable callback instead of polling, though it is a more complicated sample.
jljbascones
Posts: 3
Joined: Wed Mar 26, 2008 5:01 am

Re: null frames

Post by jljbascones »

Hello all,

I want to use a callback rather than calling GetFrame() in order to recover the information of all recorded frames in real time.
I have take a glance at the C++ VC8/2005 sample, but I would avoid the usage of the IDispEventImpl class (my c++ project is a Win32 console application).

Is there an easier way to get 'FrameAvailable' callbacks using the 'INPCameraEvents' class?

Thank you in advance.
jljbascones
Posts: 3
Joined: Wed Mar 26, 2008 5:01 am

Re: null frames

Post by jljbascones »

Hello again,

One more question is, why get I NULL frames when calling GetFrame() with INFINITE timeout? It should block the thread until a new frame is arrived, shouldn't it?
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: null frames

Post by beckdo »

You shouldn't get NULL frames when using an INFINITE timeout. It should wait indefinitely until a frame is available.
Post Reply