void AndroidVideoSource::acceptImage(ARUint8* ptr) {
	
    //ARController::logv("AndroidVideoSource::acceptImage()");
	if (deviceState == DEVICE_RUNNING) {
        if (pixelFormat == AR_PIXEL_FORMAT_NV21 || pixelFormat == AR_PIXEL_FORMAT_420f) {
            // Nothing more to do.
        } else if (ptr && pixelFormat == AR_PIXEL_FORMAT_RGBA) {
            color_convert_common((unsigned char*)ptr, (unsigned char*)(ptr + videoWidth * videoHeight), videoWidth, videoHeight, localFrameBuffer);
            
        } else {
            return;
        }
		frameStamp++;
		newFrameArrived = true;
    }
}
Exemple #2
0
/*
 * convert a yuv420 array to a rgb array
 */
JNIEXPORT void JNICALL Java_edu_dhbw_andopenglcam_CameraPreviewHandler_yuv420sp2rgb
  (JNIEnv* env, jobject object, jbyteArray pinArray, jint width, jint height, jint textureSize, jbyteArray poutArray) {
	jbyte *inArray; 
	jbyte *outArray; 
	inArray = (*env)->GetByteArrayElements(env, pinArray, JNI_FALSE);
	outArray = (*env)->GetByteArrayElements(env, poutArray, JNI_FALSE);
	//see http://java.sun.com/docs/books/jni/html/functions.html#100868
	//If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; if no copy is made, it is set to JNI_FALSE.	
	
       color_convert_common(inArray, inArray + width * height,
                 width, height, textureSize,
                 outArray, width * height * 3,
                 0, 0);

	//release arrays:
	(*env)->ReleaseByteArrayElements(env, pinArray, inArray, 0);
	(*env)->ReleaseByteArrayElements(env, poutArray, outArray, 0);
}
Exemple #3
0
JNIEXPORT void JNICALL Java_com_opencv_jni_opencvJNI_addYUVtoPool(JNIEnv * env,
		jclass thiz, jlong ppool, jobject _jpool, jbyteArray jbuffer,
		jint jidx, jint jwidth, jint jheight, jboolean jgrey) {
	image_pool *pool = (image_pool *) ppool;

	Ptr<Mat> mat = pool->getYUV(jidx);

	if (mat.empty() || mat->cols != jwidth || mat->rows != jheight * 2) {
		//pool->deleteGrey(jidx);
		mat = new Mat(jheight * 2, jwidth, CV_8UC1);
	}

	jsize sz = env->GetArrayLength(jbuffer);
	uchar* buff = mat->ptr<uchar> (0);

	env->GetByteArrayRegion(jbuffer, 0, sz, (jbyte*) buff);

	pool->addYUVMat(jidx, mat);
	Ptr<Mat> color = pool->getImage(jidx);
	if (color.empty() || color->cols != jwidth || color->rows != jheight) {
		//pool->deleteImage(jidx);
		color = new Mat(jheight, jwidth, CV_8UC3);
	}
	if (!jgrey) {

		//doesn't work unfortunately..
		//cvtColor(*mat,*color, CV_YCrCb2RGB);
		color_convert_common(buff, buff + jwidth * jheight, jwidth, jheight,
				color->ptr<uchar> (0), false);

	}

	if (jgrey) {
		Mat grey;
		pool->getGrey(jidx, grey);

		cvtColor(grey, *color, CV_GRAY2RGB);

	}

	pool->addImage(jidx, color);

}
void AndroidVideoSource::acceptImage(JNIEnv* env, jbyteArray pinArray) {

    //ARController::logv("AndroidVideoSource::acceptImage()");
    if (deviceState == DEVICE_RUNNING) {
        unsigned char *incomingBuff = NULL;
        unsigned char *convertedBuff = NULL;
        if (localFrameBuffer->buffLuma == incomingFrameRawBuffer[0]) {
            incomingBuff = incomingFrameRawBuffer[1];
            convertedBuff = convertedFrameRawBuffer[1];
        } else {
            incomingBuff = incomingFrameRawBuffer[0];
            convertedBuff = convertedFrameRawBuffer[0];
        }
        
        env->GetByteArrayRegion(pinArray, 0, incomingFrameRawBufferSize, (jbyte *)incomingBuff);
        
        if (pixelFormat == AR_PIXEL_FORMAT_RGBA) {
            color_convert_common((unsigned char *)incomingBuff, (unsigned char *)(incomingBuff + videoWidth * videoHeight), videoWidth, videoHeight, convertedBuff);
        }
        
        lockFrameBuffer();
        if (pixelFormat == AR_PIXEL_FORMAT_NV21 || pixelFormat == AR_PIXEL_FORMAT_420f) {
            localFrameBuffer->buff = incomingBuff;
            localFrameBuffer->buffLuma = incomingBuff;
            localFrameBuffer->bufPlanes[0] = incomingBuff;
            localFrameBuffer->bufPlanes[1] = incomingBuff + videoWidth*videoHeight;
        } else {
            localFrameBuffer->buff = convertedBuff;
            localFrameBuffer->buffLuma = incomingBuff;
        }
        unlockFrameBuffer();
        
        frameStamp++;
        newFrameArrived = true;
    }
}