From 6bbf1b6195f0bd402a0ec6f3d68adf64cc46f137 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 19 Sep 2024 18:04:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9C=E8=A7=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/CMakeLists.txt | 2 +- app/src/main/cpp/MicroPhoto.cpp | 8 +++- app/src/main/cpp/PhoneDevice.cpp | 47 ++++++++++++------- .../com/xypower/mpapp/MicroPhotoService.java | 1 + .../com/xypower/mpapp/video/RawActivity.java | 13 +++-- 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index f9b828f0..de146acc 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -48,7 +48,7 @@ add_definitions(-DENABLE_3V3_ALWAYS) project("microphoto") -find_package(OpenCV REQUIRED core imgproc highgui) +find_package(OpenCV REQUIRED core imgproc highgui photo) # find_package(OpenCV REQUIRED core imgproc) if(OpenCV_FOUND) include_directories(${OpenCV_INCLUDE_DIRS}) diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index a2b0f80b..939c1777 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -750,9 +750,13 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished( res = AndroidBitmap_lockPixels(env, bitmap, &pixels); cv::Mat tmp(info.height, info.width, CV_8UC4, pixels); - cv::Mat mat(info.height, info.width, CV_8UC4); + cv::Mat raw(info.height, info.width, CV_8UC4); + // tmp.copyTo(mat); - cv::cvtColor(tmp, mat, cv::COLOR_RGBA2BGR); + cv::cvtColor(tmp, raw, cv::COLOR_RGBA2BGR); + + cv::Mat mat; + cv::fastNlMeansDenoisingColored(raw, mat, 13, 13, 7, 21); AndroidBitmap_unlockPixels(env, bitmap); diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index b97aad28..d388a62e 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -1719,30 +1719,41 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat) #ifdef OUTPUT_CAMERA_DBG_INFO bool shouldRetry = false; -#if 0 - - if (captureResult.avgY > MAX_LIGHT_Y || captureResult.avgY < MIN_LIGHT_Y) - { - if (mPhotoInfo.retries < (DEFAULT_TAKE_PHOTO_RETRIES - 1)) - { - shouldRetry = true; - char presetBuf[16] = { 0 }; - snprintf(presetBuf, sizeof(presetBuf), "%02X", mPhotoInfo.retries); - // replaceAll(fullPath, ".jpg", std::string("-") + std::to_string(mPhotoInfo.retries) + ".jpg"); - replaceAll(fullPath, "_FF_", std::string("_") + presetBuf + std::string("_")); - XYLOG(XYLOG_SEVERITY_ERROR, "Photo is TOO dark or light(LDR=%u), will RETRY it", (uint32_t)captureResult.avgY); - } + if (mCamera != NULL) { + NdkCamera::CAPTURE_RESULT captureResult = mCamera->getCaptureResult(); - if (captureResult.avgY > MAX_LIGHT_Y) + if (captureResult.avgY < MIN_LIGHT_Y) { - mPhotoInfo.compensation = -2 * ((int16_t)((uint16_t)captureResult.avgY)); + if (mPhotoInfo.retries < (DEFAULT_TAKE_PHOTO_RETRIES - 1)) + { + shouldRetry = true; + char presetBuf[16] = {0}; + snprintf(presetBuf, sizeof(presetBuf), "%02X", mPhotoInfo.retries); + // replaceAll(fullPath, ".jpg", std::string("-") + std::to_string(mPhotoInfo.retries) + ".jpg"); + replaceAll(fullPath, "_FF_", std::string("_") + presetBuf + std::string("_")); + XYLOG(XYLOG_SEVERITY_ERROR, "Photo is TOO dark or light(LDR=%u), will RETRY it", + (uint32_t) captureResult.avgY); + + mPhotoInfo.usingRawFormat = 1; + } } - else + else if (captureResult.avgY > MAX_LIGHT_Y) { - mPhotoInfo.compensation = 2 * captureResult.avgY; + if (mPhotoInfo.retries < (DEFAULT_TAKE_PHOTO_RETRIES - 1)) + { + shouldRetry = true; + char presetBuf[16] = {0}; + snprintf(presetBuf, sizeof(presetBuf), "%02X", mPhotoInfo.retries); + // replaceAll(fullPath, ".jpg", std::string("-") + std::to_string(mPhotoInfo.retries) + ".jpg"); + replaceAll(fullPath, "_FF_", std::string("_") + presetBuf + std::string("_")); + XYLOG(XYLOG_SEVERITY_ERROR, "Photo is TOO dark or light(LDR=%u), will RETRY it", + (uint32_t) captureResult.avgY); + } + + mPhotoInfo.compensation = -2 * ((int16_t) ((uint16_t) captureResult.avgY)); } } -#endif + #endif // OUTPUT_CAMERA_DBG_INFO if (!std::filesystem::exists(std::filesystem::path(fullPath))) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index bc37867f..88d52b36 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -415,6 +415,7 @@ public class MicroPhotoService extends Service { @Override public void onHeaderDecoded(@NonNull ImageDecoder decoder, @NonNull ImageDecoder.ImageInfo info, @NonNull ImageDecoder.Source source) { decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE); + decoder.setTargetSize(info.getSize().getWidth(), info.getSize().getHeight()); } }; diff --git a/app/src/main/java/com/xypower/mpapp/video/RawActivity.java b/app/src/main/java/com/xypower/mpapp/video/RawActivity.java index 4a526845..165e2682 100644 --- a/app/src/main/java/com/xypower/mpapp/video/RawActivity.java +++ b/app/src/main/java/com/xypower/mpapp/video/RawActivity.java @@ -176,6 +176,8 @@ public class RawActivity extends AppCompatActivity { public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { configureTransform(width, height); + MicroPhotoService.infoLog("RawActivity onSurfaceTextureAvailable PHOTOID=" + Long.toString(mPhotoId)); + if (!mTaken) { mTaken = true; @@ -192,6 +194,8 @@ public class RawActivity extends AppCompatActivity { public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { configureTransform(width, height); + MicroPhotoService.infoLog("RawActivity onSurfaceTextureSizeChanged PHOTOID=" + Long.toString(mPhotoId)); + if (!mTaken) { mTaken = true; @@ -262,8 +266,6 @@ public class RawActivity extends AppCompatActivity { private int mOrientation = -1; - - /** * A {@link CameraCaptureSession } for camera preview. */ @@ -389,7 +391,6 @@ public class RawActivity extends AppCompatActivity { broadcastPhotoFile(false, ""); finish(); } - }; /** @@ -643,6 +644,9 @@ public class RawActivity extends AppCompatActivity { // configure the preview bounds here (otherwise, we wait until the surface is ready in // the SurfaceTextureListener). if (mTextureView.isAvailable()) { + + MicroPhotoService.infoLog("RawActivity mTextureView is Available PHOTOID=" + Long.toString(mPhotoId)); + configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); mMessageHandler.postDelayed(new Runnable() { @@ -1354,10 +1358,9 @@ public class RawActivity extends AppCompatActivity { DngCreator dngCreator = new DngCreator(mCharacteristics, mCaptureResult); FileOutputStream output = null; try { + MicroPhotoService.infoLog("RawActivity Image Size=" + Integer.toString(mImage.getWidth()) + "," + Integer.toString(mImage.getHeight())); output = new FileOutputStream(mFile); dngCreator.writeImage(output, mImage); - - mResult = true; } catch (IOException e) { e.printStackTrace();