"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Getting current image from frame from JNI

hi,

i followed one of post here to get current frame image(for RGB565) from JNI to java as byte array as below:

 

if (image->getFormat() == QCAR::RGB565){ // for rbg565, the pixels are stored as an array of shorts<br />  const short* pixels = (const short*) image->getPixels();int width = image->getWidth();int height = image->getHeight();int numPixels = width * height;jbyteArray pixelArray = env->NewByteArray(numPixels * 2);env->SetByteArrayRegion(pixelArray, 0, numPixels * 2, (const jbyte*) pixels);jclass javaClass = env->GetObjectClass(obj);jmethodID method = env->GetMethodID(javaClass, "setRGB565CameraImage", "([BII)V");env->CallObjectMethod(obj, method, pixelArray, width, height);env->DeleteLocalRef(pixelArray);} this works fine for some devices such as samsung galaxy series but same code did not work on htc and sony erricsson devices ,so going furhter i found that these devices give diffrent image PIXEL_FORMAT (YUV and others), so could you please help me out to get image byte array for other PIXEL_FORMAT such as: RGB565GRAYSCALEYUVRGBA8888
UNKNOWN_FORMAT

 

is there is any one format which i can use for diffrent devices by finding in loop,since different devices shows different behavier i am suspicious about those on which i had not tested.

AlessandroB

Tue, 12/18/2012 - 14:45

Hi, if you don't want to deal with different frame formats and just want to focus on one, you could enforce the use of a given format, using:

  QCAR::setFrameFormat( desired_pixel_format,  true );

Hi, the setFrameFormat function actually adds an extra image (the method name is also a bit misleading) to the array of images,

but that is not necessarily located at index 0 (my imprecision here), in practice it can be at index 1 or 2, depending on the device;

Here is the code that I just tested (assumption is that you have called setFrameFormat( QCAR::RGB565, true ) ):

//Global variable (ImageTargets.cpp)

QCAR::Image *imageRGB565 = NULL;

 

Hi, I did not observe that crash in my tests, however that could very well due to a threading issue

(perhaps a conflictual access to the imageRGB565 between the QCAR_onUpdate and the renderFrame);

hi ,sorry to say that doing again as you said now,htc one x is giving same error i reported ,and one thing more that if i set pixel format in initApplicationNative it has no effect in htc and sony erricsson devices.

Hi again,

I've tested on a few devices here (including Samsung and HTC); but I was unable to get the crash that you reported (using the code snippets as I reported them in the latest messages);

if I can make some suggestions: