mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
android: fix JavaCamera2View UV plane handling
This commit is contained in:
parent
b998c06d08
commit
8936a0f3a5
@ -341,11 +341,22 @@ public class JavaCamera2View extends CameraBridgeViewBase {
|
|||||||
|
|
||||||
|
|
||||||
if (chromaPixelStride == 2) { // Chroma channels are interleaved
|
if (chromaPixelStride == 2) { // Chroma channels are interleaved
|
||||||
|
assert(planes[0].getPixelStride() == 1);
|
||||||
|
assert(planes[2].getPixelStride() == 2);
|
||||||
ByteBuffer y_plane = planes[0].getBuffer();
|
ByteBuffer y_plane = planes[0].getBuffer();
|
||||||
ByteBuffer uv_plane = planes[1].getBuffer();
|
ByteBuffer uv_plane1 = planes[1].getBuffer();
|
||||||
|
ByteBuffer uv_plane2 = planes[2].getBuffer();
|
||||||
Mat y_mat = new Mat(h, w, CvType.CV_8UC1, y_plane);
|
Mat y_mat = new Mat(h, w, CvType.CV_8UC1, y_plane);
|
||||||
Mat uv_mat = new Mat(h / 2, w / 2, CvType.CV_8UC2, uv_plane);
|
Mat uv_mat1 = new Mat(h / 2, w / 2, CvType.CV_8UC2, uv_plane1);
|
||||||
Imgproc.cvtColorTwoPlane(y_mat, uv_mat, mRgba, Imgproc.COLOR_YUV2RGBA_NV21);
|
Mat uv_mat2 = new Mat(h / 2, w / 2, CvType.CV_8UC2, uv_plane2);
|
||||||
|
long addr_diff = uv_mat2.dataAddr() - uv_mat1.dataAddr();
|
||||||
|
if (addr_diff > 0) {
|
||||||
|
assert(addr_diff == 1);
|
||||||
|
Imgproc.cvtColorTwoPlane(y_mat, uv_mat1, mRgba, Imgproc.COLOR_YUV2RGBA_NV12);
|
||||||
|
} else {
|
||||||
|
assert(addr_diff == -1);
|
||||||
|
Imgproc.cvtColorTwoPlane(y_mat, uv_mat2, mRgba, Imgproc.COLOR_YUV2RGBA_NV21);
|
||||||
|
}
|
||||||
return mRgba;
|
return mRgba;
|
||||||
} else { // Chroma channels are not interleaved
|
} else { // Chroma channels are not interleaved
|
||||||
byte[] yuv_bytes = new byte[w*(h+h/2)];
|
byte[] yuv_bytes = new byte[w*(h+h/2)];
|
||||||
|
Loading…
Reference in New Issue
Block a user