From 5578b9dd068ce4987c489d85c6b3c93b4f986f63 Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Wed, 21 Feb 2024 17:13:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=85=A7=E7=89=87size?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/camera2/ndkcamera.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/cpp/camera2/ndkcamera.cpp b/app/src/main/cpp/camera2/ndkcamera.cpp index 57c08e9f..1ebedbf8 100644 --- a/app/src/main/cpp/camera2/ndkcamera.cpp +++ b/app/src/main/cpp/camera2/ndkcamera.cpp @@ -457,7 +457,6 @@ int NdkCamera::open(const std::string& cameraId) { uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_START; // status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig); m_imagesCaptured = (status == ACAMERA_OK) ? ~0 : 0; - } // TODO: @@ -744,6 +743,8 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei } */ + int orgWidth = mWidth; + int orgHeight = mHeight; // int co = camera_orientation > 0 ? camera_orientation + 90 : camera_orientation; if (m_params.orientation != 0) { @@ -771,6 +772,10 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei { w = nv21_height; h = nv21_width; + + orgWidth = mHeight; + orgHeight = mWidth; + rotate_type = camera_facing == ACAMERA_LENS_FACING_FRONT ? 5 : 6; } else if (co == 180) @@ -783,6 +788,10 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei { w = nv21_height; h = nv21_width; + + orgWidth = mHeight; + orgHeight = mWidth; + rotate_type = camera_facing == ACAMERA_LENS_FACING_FRONT ? 7 : 8; } @@ -799,7 +808,7 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei // nv21_rotated to rgb cv::Mat rgb; - if (w == mWidth && h == mHeight) + if (w == orgWidth && h == orgHeight) { rgb.create(h, w, CV_8UC3); // ncnn::yuv420sp2rgb(nv21_rotated.data, w, h, rgb.data); @@ -809,16 +818,16 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei { cv::Mat org(h, w, CV_8UC3); ncnn::yuv420sp2rgb_nv12(yuv420data, w, h, org.data); - if (w * mHeight == h * mWidth) // Same Ratio + if (w * orgHeight == h * orgWidth) // Same Ratio { - cv::resize(org, rgb, cv::Size(mWidth, mHeight)); + cv::resize(org, rgb, cv::Size(orgWidth, orgHeight)); } else { // Crop image - int left = (w - mWidth) / 2; - int top = (h - mHeight) / 2; - rgb = org(cv::Range(top, top + mHeight), cv::Range(left, left + mWidth)); + int left = (w - orgWidth) / 2; + int top = (h - orgHeight) / 2; + rgb = org(cv::Range(top, top + orgHeight), cv::Range(left, left + orgWidth)); } } on_image(rgb);