I'm making an application with optitrack, i Want to rgeister the coordinates of a point and write in a file.
Everything is ok, but I have a problem with the function get_X() of the class Object.
It's when I use it that the programs bugs.
here is my implementation...
Code: Select all
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <windows.h>
#include <time.h>
#include <math.h>
#include <cstdlib>
//--open CV--
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
//--optitrack--
#include <objbase.h>
#include <atlbase.h>
#include <optitrack.h>
#import <optitrack.tlb>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int iterMax = 100;
//-> On ouvre le fichier
fstream file("c:\\data\\NicolasJ\\text.txt",ios::out);
//-> Et on v�rifie qu'il est bien la, dans le cas contraire : erreur et fin du programme.
if(!file){
printf("Could not load image file: %s\n");
exit(0);
}
//__________________________________________________//
// //
// Proc�dure d'instanciation de la cam�ra //
// On instancie la cam�ra. //
//__________________________________________________//
//
//-> On d�clare les variables (pointeurs)
CComPtr<INPCameraCollection> cameraCollection;
CComPtr<INPCamera> camera;
CoInitialize(NULL);
cameraCollection.CoCreateInstance(CLSID_NPCameraCollection);
//-> On r�cup�re la liste des cam�ras avec la m�thode enum().
cameraCollection->Enum();
//-> Si il n'y a pas de cam�ra
long getCount=1;
if(getCount==0){
printf("Error : Pas de camera.");
cameraCollection.Release();
CoUninitialize();
return 0;
}
//-> Si on a une cam�ra, on la r�cup�re
cameraCollection->Item(0, &camera);
//-> R�cup�ration des propri�t�s de la cam�ra
long serial,width,height, rate;
camera->get_SerialNumber(&serial);
camera->get_Width (&width);
camera->get_Height (&height);
camera->get_FrameRate (&rate);
//-> Fenetre (visualisation)
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
HWND hwnd1 = (HWND)cvGetWindowHandle("mainWin");
long lg = (long)hwnd1;
//-> On d�marre la cam�ra
if (camera->Open() == S_OK){
camera->Start();
camera->SetOption(NP_OPTION_SEND_EMPTY_FRAMES, (CComVariant) true);
camera->SetOption(NP_OPTION_TEXT_OVERLAY_OPTION,(CComVariant) 255);
camera->SetOption(NP_OPTION_OBJECT_CAP,(CComVariant) 1); //(nmbre d'objet)
camera->SetOption(NP_OPTION_EXPOSURE,(CComVariant) 50);//de 0 a 399 (luminosit�) par default 150
//-> On cr�e les variables pour r�cup�rer le point.
CComPtr<INPCameraFrame> frame = 0;
CComPtr<INPObject> point = 0;
char c= '0';
while(c != 'q')
{
if (camera->GetFrame(0, &frame) == S_OK){
//Ne rentre que si il y'a une frame
if(frame!=NULL){
double *x,*y;
CComVariant *X,*Y;
// New Frame Has Arrived
camera->DrawFrame(frame, lg);
long nObjet;
frame->get_Count(&nObjet);
if (nObjet > 0){
//On rapatrie l'objet 1 de frame. (point pointe)
if(frame->Item(0,&point) == S_OK){
if(point->get_X(X) == S_OK)
;//*x=(double)(X->dblVal);
if(point->get_Y(Y)==S_OK)
;//*y=(double)(Y->dblVal);
//file.seekg(0);
//file<<*x<<" "<<*y<<endl;
point.Release();
point=NULL;
}
}
frame->Free();
frame.Release();
frame=NULL;
}
c = cvWaitKey(1);
}
}
}
camera->Stop();
camera->Close();
camera.Release();
camera = 0;
cameraCollection.Release();
CoUninitialize();
file.close();
}
Thanks a lot,
Nico