1 | initial version |
Android camera gives you frames in YUV format. You need to convert it to RGB/RGBA image before drawing them on screen. You need something like this:
mRgba = new Mat();
mYuv = new Mat(getFrameHeight() + getFrameHeight() / 2, getFrameWidth(), CvType.CV_8UC1);
mBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888);
protected Bitmap processFrame(byte[] data) {
mYuv.put(0, 0, data);
Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420sp2RGB, 4);
//process mat with native code
Utils.matToBitmap(mRgba, mBitmap);
return mBitmap;
}
mGraySubmat = mYuv.submat(0, getFrameHeight(), 0, getFrameWidth()) gives you only Y plain of YUV image that is equivalent of grace scale.