Log in or register to post comments

Grayscale Camera Frame

July 24, 2013 - 12:05am #1


I am trying to get the Grayscale camera frame and send it to the main Java part. But the app crashes while trying to do that. I am using the code below to get the grayscale and send to ImageTargets.java. When i capture RGB565 and try to send it, it sends, but with GRAYSCALE fails.


	QCAR::Frame frame = state.getFrame();

	for (int i = 0; i < frame.getNumImages(); ++i) {
		const QCAR::Image *image = frame.getImage(i);

		if (image->getFormat() == QCAR::GRAYSCALE) {
					imageGRAYSCALE = (QCAR::Image*) image;
					LOG("GRAYSCALE retained");


//controls for JavaVM and etc.

const short* pixels = ( const short*) imageGRAYSCALE->getPixels();


jbyteArray pixelArray = env->NewByteArray(numPixels * 2);

env->SetByteArrayRegion(pixelArray, 0, numPixels * 2,(const jbyte*) input);

jclass javaClass = env->GetObjectClass(ocrUtilsObj);
jmethodID method = env->GetMethodID(javaClass,
"comingFromNative", "([B)V");
env->CallVoidMethod(ocrUtilsObj, method, pixelArray);


Grayscale Camera Frame

July 24, 2013 - 1:36am #2

If you use GRAYSCALE, your pixels should consist of just 1 byte per pixel (while on RGB565, 2 bytes are used per pixel);

So  the code needs to be adapted:


const char* pixels = ( const char*) imageGRAYSCALE->getPixels();
 jbyteArray pixelArray = env->NewByteArray(  numPixels  );
env->SetByteArrayRegion(pixelArray, 0, numPixels,  (const jbyte*) input);


Log in or register to post comments