GetCamera() not working in secondary threads

Post Reply
Albinn
Posts: 2
Joined: Tue Jul 15, 2014 8:52 am

GetCamera() not working in secondary threads

Post by Albinn »

Hi,

I am integrating Camera SDK in a real time OpenGL software that can be extended through "video capture devices" plugins. Those devices are activated, deactivated and updated by the rendering thread, which is different from the program main thread.

The problem is that Camera SDK initialization fails when executed from a thread which is not the main thread.

To characterize the problem I used the following piece of code:

Code: Select all

  CameraLibrary_EnableDevelopment();
  CameraManager::X().WaitForInitialization();
 
  CameraList cameras;
  CameraManager::X().GetCameraList(cameras);
  print("Num cameras: " + cameras.Count());

  CameraLibrary::Camera* camera = CameraManager::X().GetCamera();
  CameraLibrary::Camera* camera2 = CameraManager::X().GetCamera(2);
  print("Camera: " + camera + " Camera2: " + camera2);
When executed from the program main thread, I get the following result:

Code: Select all

Num Cameras: 5
Camera: 182583360 Camera2: 182583360
The same piece of code executed in another thread gives:

Code: Select all

Num Cameras: 0
Camera: 0 Camera2: 0
Since in my case I do not have access to the program main thread, I cannot initialize Camera SDK :(

I am using Camera SDK 1.5 with 5 Flex-13 USB Cameras connected to one Optihub 2.
I am compiling in 64 bits with VS2010.

Is there any initialization trick that I am missing? Is this a restriction of Camera SDK?

Thanks for your help,

Francis.
NaturalPoint-Dustin
Posts: 609
Joined: Tue Mar 19, 2013 5:03 pm

Re: GetCamera() not working in secondary threads

Post by NaturalPoint-Dustin »

Thank you for posting on the forums. I will have a developer post a reply to your question.
Dustin
Technical Support Engineer
OptiTrack | TrackIR | SmartNav
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: GetCamera() not working in secondary threads

Post by beckdo »

Hey Francis,

The Camera SDK is multi-thread safe. Users are encouraged to implement the approach you've described if they want to fetch cameras from the Camera SDK from any thread.

There are a couple of important things to note with your approach. Calling he GetCamera() method without any parameters is a helper function that just means "give me any camera". It's best used when you only have one camera connected because you will always get the same camera.

In your case you've called GetCamera(2), which is not correct. When you have multiple cameras in the system, you'll want to use the CameraList object to see what cameras are available and then call GetCamera(cameraList[index].UID()) this will ensure that you're requesting a specific camera. You should only call GetCamera on cameras that are in State()==CameraLibrary::Initialized. The Camera SDK won't give you a camera before it's fully up and ready to be used by an application.

Then you should continue to check the CameraList at periodic intervals to pick up any cameras that become initialized.

Thx--Doug
Albinn
Posts: 2
Joined: Tue Jul 15, 2014 8:52 am

Re: GetCamera() not working in secondary threads

Post by Albinn »

Hi Doug,

Thanks for your reply!
In my case, "2" is one of the camera UIDs I get when using CameraList functions to enumerate my cameras. This was just for the example, to illustrate that the same piece of code, depending on which is the calling thread, does not lead to the same result (in reality I am using GetCamera(cameraList[index].UID()) as you mention).

To reformulate my problem: camera enumeration does not seem to work when not invoked from the main thread (even after waiting for a very long time). However, I modified my code to perform enumeration and retrieve Camera* pointers for every camera from the main thread and then do all the rest of the processing (camera start/stop and frame retrieval) from my rendering thread. This solution is working for me and thus enable to workaround the problem I mentioned (while still making the code a bit complex since I cannot check if new cameras appear in my rendering thread -- since camera enumeration do not seem to work in this thread).

Best regards,

Francis.
Post Reply