增加拍照方向的控制

serial
BlueMatthew 2 years ago
parent c409a806d4
commit 4a6b25e9ea

@ -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 <int> compression_params;
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY);
compression_params.push_back(mPhotoInfo.quality);
vector <int> 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());

@ -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<std::string, std::string>& 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);

@ -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)
{

@ -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);

@ -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) {
}

@ -100,6 +100,25 @@
app:layout_constraintTop_toTopOf="@+id/exposuretime"
app:layout_constraintBottom_toBottomOf="@+id/exposuretime" />
<TextView
android:id="@+id/textViewOrientations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="旋转角度:"
android:layout_marginStart="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/orientations"
app:layout_constraintBottom_toBottomOf="@+id/orientations" />
<Spinner
android:id="@+id/orientations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:entries="@array/orientations"
android:layout_marginStart="6dp"
android:layout_marginTop="12dp"
app:layout_constraintStart_toEndOf="@+id/textViewOrientations"
app:layout_constraintTop_toBottomOf="@+id/exposuretime" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="orientations">
<item>0</item>
<item>90</item>
<item>180</item>
<item>270</item>
</string-array>
</resources>
Loading…
Cancel
Save