增加了旋转的控制

serial
BlueMatthew 1 year ago
parent a817d4f762
commit 64c2d38e44

@ -718,65 +718,62 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei
int w = 0; int w = 0;
int h = 0; int h = 0;
int rotate_type = 0; int rotate_type = 0;
const unsigned char* yuv420data = nv21;
// TODO !!!??? // TODO !!!???
// int co = camera_orientation > 0 ? camera_orientation + 90 : camera_orientation; // int co = camera_orientation > 0 ? camera_orientation + 90 : camera_orientation;
int co = (camera_orientation + m_params.orientation * 90) % 360; if (m_params.orientation != 0)
// int co = 0;
if (co == 0)
{ {
w = nv21_width; int co = 0;
h = nv21_height; if (camera_facing == ACAMERA_LENS_FACING_FRONT)
rotate_type = camera_facing == 0 ? 2 : 1; {
} co = (camera_orientation - (m_params.orientation - 1) * 90 + 360) % 360;
if (co == 90) }
{ else
w = nv21_height; {
h = nv21_width; co = (camera_orientation + (m_params.orientation - 1) * 90) % 360;
rotate_type = camera_facing == 0 ? 5 : 6; }
// 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; w = nv21_width;
h = nv21_height; 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 // nv21_rotated to rgb
cv::Mat rgb(h, w, CV_8UC3); cv::Mat rgb(h, w, CV_8UC3);
// ncnn::yuv420sp2rgb(nv21_rotated.data, w, h, rgb.data); // ncnn::yuv420sp2rgb(nv21_rotated.data, w, h, rgb.data);
ncnn::yuv420sp2rgb_nv12(nv21_rotated.data, w, h, rgb.data); ncnn::yuv420sp2rgb_nv12(yuv420data, 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);
on_image(rgb); on_image(rgb);
} }
void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureRequest* request, const ACameraMetadata* result) void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureRequest* request, const ACameraMetadata* result)

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string-array name="orientations"> <string-array name="orientations">
<item>无旋转</item>
<item></item> <item></item>
<item>90°</item> <item>90°</item>
<item>180°</item> <item>180°</item>

Loading…
Cancel
Save