Log in or register to post comments

Get the camera object

January 28, 2011 - 8:25am #1

Hi everybody!

In my app which uses ImageTargets as its base I want the user to be able to toggle the hardware flashlight on the backside of my Desire. I dug up some splendid tutorial on how to activate said light: http://mobilecoder.wordpress.com/2010/12/06/android-torch-led/
I built a standalone test app and got the light shining flawlessly.

Now, trying to integrate the code from the tutorial into my AR-app I encountered a little problem: When calling mCamera = Camera.open(); to get a camera object, the app crashes (Fail to connect to camera service). But I somehow suspected that Android wouldn't be too happy, having two camera instances at the same time.

So my next idea was to get the already existing camera object ImageTargets is working with, from the depths of the native code.
I added getCamera() to the ImageTargets.java class to allow calls to the native code.

/** Native methods for starting, stopping and getting the camera. */ 
	private native void startCamera();
	private native void stopCamera();
	private native Camera getCamera();

Later in the ImageTargets.java class I assign the camera object like this:
mCamera = getCamera();

And now to the core of my problem: How should my getCamera() method in the ImageTargets.cpp native class look like?

Certainly not like this:

JNIEXPORT Camera JNICALL
	Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_getCamera(JNIEnv *, jobject)
	{
		return QCAR::CameraDevice::getInstance();
	}

As the type Camera is unknown to the compiler. The return type QCAR::CameraDevice didn't work either as there are some purely virtual functions in CameraDevice (the compiler told me so).

So here's my question: How do I get an instance of the camera available in ImageTargets.java in order to activate the phone's flashlight?

Many greetings and thanks in advance!

Matthias

Get the camera object

December 16, 2013 - 9:53am #4

I used Unity to access the camera's light:

CameraDevice.Instance.SetFlashTorchMode(true)

 

Best,

Matthias

AttachmentSize
Binary Data bytes

Get the camera object

December 16, 2013 - 7:17am #3

Matthias wrote:

Hi everybody! In my app which uses ImageTargets as its base I want the user to be able to toggle the hardware flashlight on the backside of my Desire. I dug up some splendid tutorial on how to activate said light: http://mobilecoder.wordpress.com/2010/12/06/android-torch-led/ I built a standalone test app and got the light shining flawlessly. Now, trying to integrate the code from the tutorial into my AR-app I encountered a little problem: When calling

mCamera = Camera.open();

to get a camera object, the app crashes (Fail to connect to camera service). But I somehow suspected that Android wouldn't be too happy, having two camera instances at the same time. So my next idea was to get the already existing camera object ImageTargets is working with, from the depths of the native code. I added getCamera() to the ImageTargets.java class to allow calls to the native code.

/** Native methods for starting, stopping and getting the camera. */ private native void startCamera(); private native void stopCamera(); private native Camera getCamera();

Later in the ImageTargets.java class I assign the camera object like this:

mCamera = getCamera();

And now to the core of my problem: How should my getCamera() method in the ImageTargets.cpp native class look like? Certainly not like this:

JNIEXPORT Camera JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_getCamera(JNIEnv *, jobject) { return QCAR::CameraDevice::getInstance(); }

As the type Camera is unknown to the compiler. The return type QCAR::CameraDevice didn't work either as there are some purely virtual functions in CameraDevice (the compiler told me so). So here's my question: How do I get an instance of the camera available in ImageTargets.java in order to activate the phone's flashlight? Many greetings and thanks in advance! Matthias

Hello Matthias,

did you achieve your goal and how?

Thanks for the help!

Re: Get the camera object

January 28, 2011 - 10:24am #2

Unfortunately this isn't possible with the current version of the SDK. The internal library has full ownership of the camera, and there is no way to get a handle to the camera object.

We have had a few requests for this feature, however, and it might show up in a future release of the SDK.

- Kim

Log in or register to post comments