1 | initial version |
I have been able to do it successfully.
Image.Plane Y = image.getPlanes()[0];
Image.Plane U = image.getPlanes()[1];
Image.Plane V = image.getPlanes()[2];
int Yb = Y.getBuffer().remaining();
int Ub = U.getBuffer().remaining();
int Vb = V.getBuffer().remaining();
byte[] data = new byte[Yb + Ub + Vb];
Y.getBuffer().get(data, 0, Yb);
U.getBuffer().get(data, Yb, Ub);
V.getBuffer().get(data, Yb+ Ub, Vb);
I'm using OpenCV JNI and was able to convert it to BGR image using CV_YUV2BGR_I420
with cvtColor
Here's my C++ code.
jboolean Java_com_fenchtose_myPackage_myClass_myMethod(
JNIEnv* env, jobject thiz,
jint width, jint height,
jbyteArray YUVFrameData)
{
jbyte * pYUVFrameData = env->GetByteArrayElements(YUVFrameData, 0);
double alpha;
alpha = (double) alphaVal;
Mat mNV(height + height/2, width, CV_8UC1, (unsigned char*)pYUVFrameData);
Mat mBgr(height, width, CV_8UC3);
cv::cvtColor(mNV, mBgr, CV_YUV2BGR_I420);
env->ReleaseByteArrayElements(YUVFrameData, pYUVFrameData, 0);
return true;
}