SDK 1.0 Final Callback Method

Share source code samples for use with the Camera SDK
Post Reply
avelazquez
Posts: 19
Joined: Mon Jun 07, 2010 7:40 am

SDK 1.0 Final Callback Method

Post by avelazquez »

I have written an application utilizing the callback method to handle the arrival of frames (using SDK 1.0 Final). I based it of my previous application utilizing SDK37 in vc++. My callback does not work and I can't find the problem with it.

I am interested specifically on making the callback method work, I have utilized the polling method and although it works, it does not satisfy my needs.


Thanks!



//globally defined Camera object
CameraLibrary::Camera *NewCamera;
CameraLibrary::Frame *pframe;




class cMyOtherClass:public cCameraListener
{
public:
STDMETHOD_(void, OnFrameAvailable)(CameraLibrary::Camera *pCamera) { HandleFrameAvailable(pCamera); }

//---------------------------------------------------------------------------------------------------------------------------
void HandleFrameAvailable(CameraLibrary::Camera *pCamera);

};
cMyOtherClass *processFrame;













//============================================================================================================
//the class below contains InitiOPtitrack, ShutdownOptitrac functions

class cStartStop
{
public:


//---------------------------------------------------------------------------------------------------


void InitOptiTrack ()
{
lngFrameCount = 0;


//== Initialize connected cameras ==========----

CameraManager::X().WaitForInitialization();

//== Get a connected camera ================----
NewCamera=CameraManager::X().GetCamera(); // Camera *camera =

//== If no device connected, pop a message box and exit ==--

if(camera==0)
{
MessageBox::Show("Please connect a camera","No Device Connected");
return;
}


//this is where I do attachListener
NewCamera->AttachListener(processFrame); //== Attach for camera events =======---

NewCamera->Start();


}


//---------------------------------------------------------------------------------------------------



void ShutdownOptiTrack ()

{

//== Release camera ==--

NewCamera->Release();


//== Remove camera listener =========---
NewCamera->RemoveListener(processFrame);

//== Shutdown Camera Library ==--

CameraManager::X().Shutdown();


}



};
cStartStop theCamera;

//==============================================================================================




//here is where I handle the frame
void cMyOtherClass::HandleFrameAvailable(CameraLibrary::Camera * pCamera)
{
...do something
}
VincentG
Posts: 7728
Joined: Mon Jul 17, 2006 5:00 am
Location: Corvallis, Oregon

Re: SDK 1.0 Final Callback Method

Post by VincentG »

answered via email
asuteau
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

Re: SDK 1.0 Final Callback Method

Post by asuteau »

Hello,
I'm currently working on attaching a listener to my camera and I'd like to know how you solved the problem.

Right now, my callback is working without any problem but I can't even retrieve a pointer to my camera object, because the FrameAvailable() declared in cCameraListener class has no parameter at all.

I've tried the solution posted by OptiAl and something is missing...
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: SDK 1.0 Final Callback Method

Post by beckdo »

The cCameraListener was intended to be hooked to a single camera, that way you'd already know that it was the camera you hooked to that had a new frame. Alternatively if you wanted to hook a single object to all the camera's and listen then you could just call GetFrame on each camera whenever the FrameAvailable() triggers and see which camera returns a frame.
asuteau
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

Re: SDK 1.0 Final Callback Method

Post by asuteau »

Hello Doug,

Thanks for you answer, now I understand better the purpose of cCameraListener listener.
Actually, I think I'll not handle events when a new frame available, because my actual purpose is to handle multiple cameras.

I've a class which inherits from CameraManagerListener. Then I've registered events to the camera manager by using RegisterListener(), but the fact is that I can then detect camera connection/disconnection but without knowing which camera has been connected/disconnected.
However, it seems to be very well handled in visualbin application which is installed with Camera SDK.

So is there any way to add connection/disconnection events directly to a Camera, and not to the CameraManager ?

Thanks for your answer.

Regards,
Aymeric.
asuteau
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

Re: SDK 1.0 Final Callback Method

Post by asuteau »

No solution at all ?
I think I could be really useful to create a sticky thread concerning callback implementation.
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: SDK 1.0 Final Callback Method

Post by beckdo »

Yeah, that's certainly reasonable. So if I understand what you're saying you'd like the cCameraListener to also hear connect & disconnect callbacks from the camera as well as connection/disconnect callbacks you can hear from the CameraManager.

The main reason these don't come from the camera directly is because when a camera connects you haven't had a chance to attach a listener to it. You don't have access to cameras until they've connected. However it's possible to have a camera callback when it's disconnected. That could be a useful callback that is currently only reported by the CameraManager's callbacks.
asuteau
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

Re: SDK 1.0 Final Callback Method

Post by asuteau »

Hello Doug, thanks for your answer.

To answer your question, actually I understand why it's not possible to attach Connect and Disconnect events to the Camera listener.
My real question was about Connect/Disconnect events attached to the CameraManager listener. Indeed, 2 callbacks are available which must be declared as follows :
void CameraConnected();
void CameraDisconnected();


So using these 2 callbacks, you can be noticed as soon as an Optitrack camera is connected or disconnected. But these callbacks don't have any parameter, or maybe I'm not using them correctly.
For example, if there was a cookie as a parameter (void* cookie) as we usually see in callbacks, it would be possible to retrieve a Camera object and know exactly which device has been connected or disconnected.
Post Reply