From 64c2d38e4454b446282d7759a25c03ca02438ec8 Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Tue, 16 Jan 2024 18:16:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=97=8B=E8=BD=AC?= =?UTF-8?q?=E7=9A=84=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/camera2/ndkcamera.cpp | 87 ++++++++++++------------ app/src/main/res/values/orientations.xml | 1 + 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/app/src/main/cpp/camera2/ndkcamera.cpp b/app/src/main/cpp/camera2/ndkcamera.cpp index b9e80800..09018c7f 100644 --- a/app/src/main/cpp/camera2/ndkcamera.cpp +++ b/app/src/main/cpp/camera2/ndkcamera.cpp @@ -718,65 +718,62 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei int w = 0; int h = 0; int rotate_type = 0; + const unsigned char* yuv420data = nv21; // TODO !!!??? // int co = camera_orientation > 0 ? camera_orientation + 90 : camera_orientation; - int co = (camera_orientation + m_params.orientation * 90) % 360; - // int co = 0; - if (co == 0) + if (m_params.orientation != 0) { - w = nv21_width; - h = nv21_height; - rotate_type = camera_facing == 0 ? 2 : 1; - } - if (co == 90) - { - w = nv21_height; - h = nv21_width; - rotate_type = camera_facing == 0 ? 5 : 6; + int co = 0; + if (camera_facing == ACAMERA_LENS_FACING_FRONT) + { + co = (camera_orientation - (m_params.orientation - 1) * 90 + 360) % 360; + } + else + { + co = (camera_orientation + (m_params.orientation - 1) * 90) % 360; + } + // int co = 0; + if (co == 0) + { + w = nv21_width; + h = nv21_height; + rotate_type = camera_facing == 0 ? 2 : 1; + } + if (co == 90) + { + w = nv21_height; + h = nv21_width; + rotate_type = camera_facing == 0 ? 5 : 6; + } + if (co == 180) + { + w = nv21_width; + h = nv21_height; + rotate_type = camera_facing == 0 ? 4 : 3; + } + if (co == 270) + { + w = nv21_height; + h = nv21_width; + rotate_type = camera_facing == 0 ? 7 : 8; + } + + cv::Mat nv21_rotated(h + h / 2, w, CV_8UC1); + ncnn::kanna_rotate_yuv420sp(nv21, nv21_width, nv21_height, nv21_rotated.data, w, h, rotate_type); + yuv420data = nv21_rotated.data; } - if (co == 180) + else { w = nv21_width; h = nv21_height; - rotate_type = camera_facing == 0 ? 4 : 3; - } - if (co == 270) - { - w = nv21_height; - h = nv21_width; - rotate_type = camera_facing == 0 ? 7 : 8; } -#if 0 - cv::Mat nv21_rotated(h + h / 2, w, CV_8UC1); - ncnn::kanna_rotate_yuv420sp(nv21, nv21_width, nv21_height, nv21_rotated.data, w, h, rotate_type); - -#ifdef _DEBUG - if (nv21_rotated.empty()) - { - int aa = 0; - } -#endif - // nv21_rotated to rgb cv::Mat rgb(h, w, CV_8UC3); // ncnn::yuv420sp2rgb(nv21_rotated.data, w, h, rgb.data); - ncnn::yuv420sp2rgb_nv12(nv21_rotated.data, w, h, rgb.data); -#else - - w = nv21_width; - h = nv21_height; - - // nv21_rotated to rgb - cv::Mat rgb(h, w, CV_8UC3); - // ncnn::yuv420sp2rgb(nv21_rotated.data, w, h, rgb.data); - ncnn::yuv420sp2rgb_nv12(nv21, w, h, rgb.data); -#endif // 0 - // cv::Mat rgb(h, w, CV_8UC3); - // ncnn::yuv420sp2rgb_nv12(nv21, w, h, rgb.data); + ncnn::yuv420sp2rgb_nv12(yuv420data, w, h, rgb.data); on_image(rgb); - } void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureRequest* request, const ACameraMetadata* result) diff --git a/app/src/main/res/values/orientations.xml b/app/src/main/res/values/orientations.xml index 751c02e2..3274fa4e 100644 --- a/app/src/main/res/values/orientations.xml +++ b/app/src/main/res/values/orientations.xml @@ -1,6 +1,7 @@ + 无旋转 90° 180°