修复照片size的bug

serial
BlueMatthew 1 year ago
parent 980b9b3b66
commit 5578b9dd06

@ -457,7 +457,6 @@ int NdkCamera::open(const std::string& cameraId) {
uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_START; uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_START;
// status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig); // status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
m_imagesCaptured = (status == ACAMERA_OK) ? ~0 : 0; m_imagesCaptured = (status == ACAMERA_OK) ? ~0 : 0;
} }
// TODO: // 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; // int co = camera_orientation > 0 ? camera_orientation + 90 : camera_orientation;
if (m_params.orientation != 0) 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; w = nv21_height;
h = nv21_width; h = nv21_width;
orgWidth = mHeight;
orgHeight = mWidth;
rotate_type = camera_facing == ACAMERA_LENS_FACING_FRONT ? 5 : 6; rotate_type = camera_facing == ACAMERA_LENS_FACING_FRONT ? 5 : 6;
} }
else if (co == 180) 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; w = nv21_height;
h = nv21_width; h = nv21_width;
orgWidth = mHeight;
orgHeight = mWidth;
rotate_type = camera_facing == ACAMERA_LENS_FACING_FRONT ? 7 : 8; 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 // nv21_rotated to rgb
cv::Mat rgb; cv::Mat rgb;
if (w == mWidth && h == mHeight) if (w == orgWidth && h == orgHeight)
{ {
rgb.create(h, w, CV_8UC3); rgb.create(h, w, CV_8UC3);
// ncnn::yuv420sp2rgb(nv21_rotated.data, w, h, rgb.data); // 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); cv::Mat org(h, w, CV_8UC3);
ncnn::yuv420sp2rgb_nv12(yuv420data, w, h, org.data); 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 else
{ {
// Crop image // Crop image
int left = (w - mWidth) / 2; int left = (w - orgWidth) / 2;
int top = (h - mHeight) / 2; int top = (h - orgHeight) / 2;
rgb = org(cv::Range(top, top + mHeight), cv::Range(left, left + mWidth)); rgb = org(cv::Range(top, top + orgHeight), cv::Range(left, left + orgWidth));
} }
} }
on_image(rgb); on_image(rgb);

Loading…
Cancel
Save