point cloud sdk 2 seconds delay

Post Reply
wipe
Posts: 2
Joined: Mon Oct 13, 2008 2:48 am

point cloud sdk 2 seconds delay

Post by wipe » Tue Oct 28, 2008 6:46 am

Hi,

I am developing a simple application that renders a point in the 3d position of a marker that I am getting with the PointCloud sdk but I am getting like a 2 seconds delay.

My OS is Windows XP SP2 , I am using 4 cameras(with the synchronized cables connected). All of them are directly connected to the pc. I've already desactivated the power saving checkbox of the usb root hubs in the device manager without any improvement.

What it surprises me is that on the results of the camera calibration tool I am not getting any delay in the visualization of the marker, it reacts quite fast according
with the movements of the marker, so that makes me think that could be something related with my code.

But is based on the point cloud visual studio example (without sleeping the main loop and getting the coordinates from every frame ), and I've just added OpenGL for visualizing the tracked point .

I have been checking on the forums but I didn't find a solution for my problem. Any suggestions?

Thanks in advance.

beckdo
NaturalPoint Employee
NaturalPoint Employee
Posts: 519
Joined: Tue Jan 02, 2007 2:02 pm

Re: point cloud sdk 2 seconds delay

Post by beckdo » Tue Oct 28, 2008 9:51 am

the most likely problem here is that you're not polling for the data often enough. To ensure that you're keeping the que of new data empty, call GetFrame() and process each frame until GetFrame() returns NULL. That's how you'll know you're caught up.

wipe
Posts: 2
Joined: Mon Oct 13, 2008 2:48 am

Re: point cloud sdk 2 seconds delay

Post by wipe » Mon Dec 08, 2008 10:58 am

thanks for the fast answer.

Finally I tried with the non-Com c++ code sample and it works fine, without delay. I couldn't get rid of the delay problem with the com c++ sample though.

beckdo
NaturalPoint Employee
NaturalPoint Employee
Posts: 519
Joined: Tue Jan 02, 2007 2:02 pm

Re: point cloud sdk 2 seconds delay

Post by beckdo » Mon Dec 08, 2008 2:55 pm

Feel free to send over your source if you'd like me to take a look at it.

DAMACA
Posts: 8
Joined: Wed Jan 28, 2009 9:29 am

Re: point cloud sdk 2 seconds delay

Post by DAMACA » Tue May 19, 2009 2:30 pm

Hello,

I am having the same problem, I have a few seconds delay when I make the markers reconstruction, this is my code.

I really appreciate any help you can give me.

[size:8pt]#include
#include
#include "./optitrack.h"
#import "./optitrack.tlb"
#include "iostream"
#include
#include
#include
#include
#include
#include
#include
#include
#include "./PointCloud.h"
#import "./PointCloud.tlb"
#include
#include
#include
#include "stdafx.h"




#define IDC_STATIC_FRAME_IMAGE 1038
using namespace std;


bool Para=false;
bool CargarPerfil=false;

//posiciones en X y Y de las camaras 0 a 1
double xa,ya,za;
double xb,yb,zb;
double xc,yc,zc;
//Posicion inicial de la escena
double xpv=0;
double ypv=0;
double z=-20;
//contador para realizar la carga del perfil una sola vez
int una=0;
int frameCounter = 0;
//Rotacion del punto de vista de la escena
double rotationY;
double rotationZ;
double rotationX;
//
char *folder;
double xmrc=0, ymrc=0, zmrc=0;

CComPtr frame;
CComPtr pointCloud;
CComPtr point;
CComPtr camaraC;
HRESULT resultado;

void Reshape(int ancho, int alto)
{
if(alto==0)
{
alto=1;
}
glViewport(0,0,ancho,alto);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

//el ultimo valor es la profundidad

gluPerspective(45.0f,(GLfloat)ancho/(GLfloat)alto,0.1f,1000.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}
void InitGl(GLvoid)
{
CoInitialize(NULL);
glClearColor(0.0f,0.0f,0.0f,0.5f);
glClearDepth(1.0f);
glClearStencil(0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
//se crea aca porque solo se ejecta una vez
pointCloud.CoCreateInstance(_uuidof(NPPointCloud));
BSTR Filename = ::SysAllocString(L"Calibration Result.cal");
resultado = pointCloud->LoadProfile(Filename);
long cameraCount;
pointCloud->get_CameraCount(&cameraCount);


printf("******************APLICACION LABORATORIO DE REALIDAD VIRTUAL******************\n\n");
printf("Daniel M Calderon Yepes\n\n");
printf("******************************************************************************\n\n");
printf("Informacion:\n\n");
printf("a: Traslada el punto de vista de la escena a la izquierda\n");
printf("d: Traslada el punto de vista de la escena a la derecha\n");
printf("w: Traslada el punto de vista de la escena arriba\n");
printf("s: Traslada el punto de vista de la escena abajo\n\n");
printf("i: Zoom in\n");
printf("o: Zoom out\n\n");
printf("Flecha Arriba/Abajo: Rota el punto de vista de la escena sobre el eje Z\n");
printf("Flecha Izquierda/Derecha: Rota el punto de vista de la escena sobre el eje Y\n\n");
printf("ESC: Salir\n\n" );
printf("******************************************************************************\n\n");
printf("El Perfil de calibracion debe encontrase en la misma carpeta\n");
printf("que el proyecto para poder ser cargado\n\n");
printf("******************************************************************************\n\n");


switch(resultado)
{
case NP_POINTCLOUD_FILE_NOT_FOUND:
printf("Perfil de calibracion no encontrado");
break;

case NP_POINTCLOUD_LOAD_FAILED:
printf("Falla al cargar el perfil de calibracion");
break;

case NP_POINTCLOUD_FAILED:
printf("Carga fallida");
break;

default:
break;
}
if(resultado==S_OK)
{
printf("Perfil encontrado y cargado");


//Obtenemos las cordenadas X,Y y Z para la camara 0
pointCloud->GetCamera(0,&camaraC);
camaraC->get_X(&xa);
camaraC->get_Y(&ya);
camaraC->get_Z(&za);

camaraC.Release();

//Obtenemos las cordenadas X,Y y Z para la camara 1
pointCloud->GetCamera(1,&camaraC);
camaraC->get_X(&xb);
camaraC->get_Y(&yb);
camaraC->get_Z(&zb);

camaraC.Release();

//Obtenemos las cordenadas X,Y y Z para la camara 2
pointCloud->GetCamera(2,&camaraC);
camaraC->get_X(&xc);
camaraC->get_Y(&yc);
camaraC->get_Z(&zc);

camaraC.Release();
}
pointCloud->Start(); //== Start capturing 3D marker data ===========---


}
void Keyboard(unsigned char key,int x, int y)
{
switch(key)
{
//Salir cuando presiona ESC
case 27:

pointCloud->Stop();
pointCloud.Release();
CoUninitialize();

exit(0);
break;
case 0x63:
CargarPerfil=true;
break;
//Zoom in cuando presiona i o I
case 0x69:
case 0x49:
z+=1.0f;
break;
//Zoom out cuando presiona o u O
case 0x6f:
case 0x4f:
z-=1.0f;
break;
//Mover punto de vista a la derecha cuando presiona d o D
case 0x64:
case 0x44:
xpv+=1.0f;
break;
//Mover punto de vista a la izquierda cuando presiona a o A
case 0x61:
case 0x41:
xpv-=1.0f;
break;
//Mover punto de vista arriba cuando presiona w o W
case 0x77:
case 0x57:
ypv+=1.0f;
break;
//Mover punto de vista abajo cuando presiona s o S
case 0x73:
case 0x53:
ypv-=1.0f;
break;

default:
break;
}
}

void Flechas(int a_key, int x, int y)
{
switch(a_key)
{
case GLUT_KEY_UP:
rotationZ-=1.0f;
break;
case GLUT_KEY_DOWN:
rotationZ+=1.0f;
break;

case GLUT_KEY_RIGHT:
rotationY=rotationY+1.0f;
break;
case GLUT_KEY_LEFT:
rotationY=rotationY-1.0f;
break;
default:
break;
}
}
void DibujarMrc()
{

glPushMatrix();
glTranslatef(xmrc*30,ymrc*30,zmrc*30);
glColor3f(0.0f,1.0f,0.0f);
glutSolidSphere(0.2,100,100);
glEnd();
glPopMatrix();
//glutSwapBuffers();

}

void PosicionMarcadores()
{

pointCloud->GetFrame(&frame);

if(frame!=NULL)
{
long markerCount;

frame->get_Count(&markerCount);

if(markerCount>=1)
{

for(int j=0;jItem(j, &point); //== Get 3D Marker Details =====---

if(point!=NULL)
{
point->get_X(&xmrc); //== Get marker location =======---
point->get_Y(&ymrc);
point->get_Z(&zmrc);
DibujarMrc();

}
point.Release(); //== Done with point, release it ======---
}
}
frame.Release(); //== Done with frame, release it ======---
}
//
}

void Display()
{

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);

//Modificacion de los puntos de vista de la escena
glTranslatef(xpv,ypv,z);
glRotatef(rotationY,0.0f,1.0f,0.0f);
glRotatef(rotationX,1.0f,0.0f,0.0f);
glRotatef(rotationZ,0.0f,0.0f,1.0f);

PosicionMarcadores();


//nos trasladamos a la posicion de la camara 0
//Dibujamos un cubo
glPushMatrix();
glTranslatef(xa*30,ya*30,za*30);
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_QUADS);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(1.0f,1.0f,1.0f);

glColor3f(1.0f,0.5f,0.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);

glColor3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);

glColor3f(1.0f,1.0f,0.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(1.0f,1.0f,-1.0f);

glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);

glColor3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(1.0f,1.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);

glEnd();
glPopMatrix();
//nos trasladamos a la posicion de la camara 1
//Dibujamos un cubo
glPushMatrix();
glTranslatef(xb*30,yb*30,zb*30);
glColor3f(1.0f,0.1f,0.1f);
glBegin(GL_QUADS);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(1.0f,1.0f,1.0f);

glColor3f(1.0f,0.5f,0.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);

glColor3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);

glColor3f(1.0f,1.0f,0.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(1.0f,1.0f,-1.0f);

glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);

glColor3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(1.0f,1.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);

glEnd();
glPopMatrix();
//nos trasladamos a la posicion de la camara 2
//Dibujamos un cubo
glPushMatrix();
glTranslatef(xc*30,yc*30,zc*30);
glColor3f(1.0f,0.1f,0.1f);
glBegin(GL_QUADS);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(1.0f,1.0f,1.0f);

glColor3f(1.0f,0.5f,0.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);

glColor3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);

glColor3f(1.0f,1.0f,0.0f);
glVertex3f(1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(1.0f,1.0f,-1.0f);

glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,1.0f,1.0f);
glVertex3f(-1.0f,1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,1.0f);

glColor3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,1.0f,-1.0f);
glVertex3f(1.0f,1.0f,1.0f);
glVertex3f(1.0f,-1.0f,1.0f);
glVertex3f(1.0f,-1.0f,-1.0f);


glEnd();
glPopMatrix();

glutSwapBuffers();


}
void main(int argc, char** argv)
{
folder=argv[0];
glutInit(&argc, argv);
glutInitWindowSize(500,500);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_STENCIL|GLUT_DEPTH);
glutCreateWindow(argv[0]);
glutFullScreen();
InitGl();
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Keyboard);
glutSpecialFunc(Flechas);
glutIdleFunc(Display);
glutMainLoop();

}[/size]


Thanks in advance

Post Reply