From 4a6b25e9ea53a012f2d4afb83a49796ab437636a Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Fri, 1 Dec 2023 16:21:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8B=8D=E7=85=A7=E6=96=B9?= =?UTF-8?q?=E5=90=91=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/PhoneDevice.cpp | 13 +++++++------ app/src/main/cpp/PhoneDevice.h | 4 ++-- app/src/main/cpp/camera2/ndkcamera.cpp | 4 ++-- app/src/main/cpp/camera2/ndkcamera.h | 4 +++- .../com/xypower/mpapp/ChannelActivity.java | 3 +++ app/src/main/res/layout/activity_channel.xml | 19 +++++++++++++++++++ app/src/main/res/values/orientations.xml | 9 +++++++++ 7 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/values/orientations.xml diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 3619d161..01050552 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -140,7 +140,7 @@ CPhoneDevice::CPhoneCamera::CPhoneCamera(CPhoneDevice* dev, int32_t width, int32 { } -bool CPhoneDevice::CPhoneCamera::on_image(const cv::Mat& rgb) +bool CPhoneDevice::CPhoneCamera::on_image(cv::Mat& rgb) { if (m_dev != NULL) { @@ -613,6 +613,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< params.autoExposure = mPhotoInfo.autoExposure; params.exposureTime = mPhotoInfo.exposureTime; params.sensibility = mPhotoInfo.sensibility; + params.orientation = mPhotoInfo.orientation; mCamera = new CPhoneCamera(this, photoInfo.width, photoInfo.height, params); if (mCamera->open(to_string(mPhotoInfo.cameraId).c_str()) == 0) @@ -648,7 +649,7 @@ void CPhoneDevice::CloseCamera2(CPhoneDevice::CPhoneCamera* camera) delete camera; } -bool CPhoneDevice::OnImageReady(const cv::Mat& mat) +bool CPhoneDevice::OnImageReady(cv::Mat& mat) { mPhotoInfo.photoTime = time(NULL); int baseline = 0; @@ -713,15 +714,15 @@ bool CPhoneDevice::OnImageReady(const cv::Mat& mat) } - vector compression_params; - compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); - compression_params.push_back(mPhotoInfo.quality); + vector params; + params.push_back(cv::IMWRITE_JPEG_QUALITY); + params.push_back(mPhotoInfo.quality); bool res = false; std::string fullPath = mPath + CTerminal::BuildPhotoFileName(mPhotoInfo); if (!std::filesystem::exists(std::filesystem::path(fullPath))) { - bool res = cv::imwrite(fullPath.c_str(), mat, compression_params); + bool res = cv::imwrite(fullPath.c_str(), mat, params); if (!res) { ALOGE("Failed to write photo: %s", fullPath.c_str()); diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 62418bba..1b4a6243 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -32,7 +32,7 @@ public: class CPhoneCamera : public NdkCamera { public: CPhoneCamera(CPhoneDevice* dev, int32_t width, int32_t height, const NdkCamera::CAMERA_PARAMS& params); - virtual bool on_image(const cv::Mat& rgb); + virtual bool on_image(cv::Mat& rgb); virtual void on_error(const std::string& msg); protected: @@ -82,7 +82,7 @@ protected: void QueryPowerInfo(std::map& powerInfo); std::string QueryCpuTemperature(); - bool OnImageReady(const cv::Mat& mat); + bool OnImageReady(cv::Mat& mat); void onError(const std::string& msg); static void CloseCamera2(CPhoneCamera* camera); diff --git a/app/src/main/cpp/camera2/ndkcamera.cpp b/app/src/main/cpp/camera2/ndkcamera.cpp index b75c70b5..1b41004d 100644 --- a/app/src/main/cpp/camera2/ndkcamera.cpp +++ b/app/src/main/cpp/camera2/ndkcamera.cpp @@ -589,7 +589,7 @@ void NdkCamera::on_error(const std::string& msg) { } -bool NdkCamera::on_image(const cv::Mat& rgb) +bool NdkCamera::on_image(cv::Mat& rgb) { return false; } @@ -603,7 +603,7 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei int rotate_type = 0; // TODO !!!??? // int co = camera_orientation > 0 ? camera_orientation + 90 : camera_orientation; - int co = (camera_orientation + 90) % 360; + int co = (camera_orientation + m_params.orientation * 90) % 360; // int co = 0; if (co == 0) { diff --git a/app/src/main/cpp/camera2/ndkcamera.h b/app/src/main/cpp/camera2/ndkcamera.h index e9fabc3b..b861b537 100644 --- a/app/src/main/cpp/camera2/ndkcamera.h +++ b/app/src/main/cpp/camera2/ndkcamera.h @@ -42,6 +42,8 @@ public: unsigned int nightMode : 1; unsigned int autoFocus : 1; unsigned int autoExposure : 1; + unsigned int orientation:2; + unsigned int reserved : 26; unsigned int exposureTime; // ms unsigned int sensibility; }; @@ -54,7 +56,7 @@ public: void close(); void onImageAvailable(AImageReader* reader); - virtual bool on_image(const cv::Mat& rgb); + virtual bool on_image(cv::Mat& rgb); virtual void on_error(const std::string& msg); virtual void on_image(const unsigned char* nv21, int nv21_width, int nv21_height); diff --git a/app/src/main/java/com/xypower/mpapp/ChannelActivity.java b/app/src/main/java/com/xypower/mpapp/ChannelActivity.java index 7ea00841..a530cb4d 100644 --- a/app/src/main/java/com/xypower/mpapp/ChannelActivity.java +++ b/app/src/main/java/com/xypower/mpapp/ChannelActivity.java @@ -117,6 +117,7 @@ public class ChannelActivity extends AppCompatActivity { binding.btnHdrMode.setChecked(jsonObject.optInt("hdr", 1) == 1); binding.exposuretime.setText(Integer.toString(jsonObject.optInt("exposureTime", 0))); binding.sensitivity.setText(Integer.toString(jsonObject.optInt("sensibility", 0))); + binding.orientations.setSelection(jsonObject.optInt("orientation", 0)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); @@ -194,6 +195,8 @@ public class ChannelActivity extends AppCompatActivity { jsonObject.put("hdrMode", binding.btnHdrMode.isChecked() ? 1 : 0); jsonObject.put("exposureTime", Integer.parseInt(binding.exposuretime.getText().toString())); jsonObject.put("sensibility", Integer.parseInt(binding.sensitivity.getText().toString())); + jsonObject.put("orientation", binding.orientations.getSelectedItemPosition()); + } catch (JSONException ex) { } diff --git a/app/src/main/res/layout/activity_channel.xml b/app/src/main/res/layout/activity_channel.xml index 38ab5638..c3a13927 100644 --- a/app/src/main/res/layout/activity_channel.xml +++ b/app/src/main/res/layout/activity_channel.xml @@ -100,6 +100,25 @@ app:layout_constraintTop_toTopOf="@+id/exposuretime" app:layout_constraintBottom_toBottomOf="@+id/exposuretime" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/orientations.xml b/app/src/main/res/values/orientations.xml new file mode 100644 index 00000000..8b4c6ed4 --- /dev/null +++ b/app/src/main/res/values/orientations.xml @@ -0,0 +1,9 @@ + + + + 0 + 90 + 180 + 270 + + \ No newline at end of file