diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 6e7f0fe3..785ebd20 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -1241,6 +1241,41 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat) cv::Scalar scalarRed(0, 0, 255); // red NdkCamera::CAPTURE_RESULT captureResult = mCamera->getCaptureResult(); + + if (captureResult.avgY < 25 && mPhotoInfo.autoExposure != 0) + { + // Take another photo + CPhoneDevice* pThis = this; + std::string path = mPath; + IDevice::PHOTO_INFO photoInfo = mPhotoInfo; + std::vector osds = mOsds; + + photoInfo.photoId += 1; + photoInfo.autoExposure = 0; + if (captureResult.avgY == 0) + { + photoInfo.exposureTime = 400; + photoInfo.sensitivity = 2000; + } + else + { + photoInfo.exposureTime = captureResult.exposureTime / 100000 * 120 / captureResult.avgY; + photoInfo.sensitivity = photoInfo.sensitivity * 60 / captureResult.avgY; + if (photoInfo.sensitivity > 2000) + { + photoInfo.sensitivity = 2000; + } + } + + std::thread t([=] + { + std::this_thread::sleep_for(std::chrono::milliseconds(5000)); + pThis->TakePhoto(photoInfo, osds, path); + }); + + t.detach(); + } + char extimeunit[4] = { 0 }; unsigned int extime = (captureResult.exposureTime >= 1000000) ? ((unsigned int)(captureResult.exposureTime / 1000000)) : ((unsigned int)(captureResult.exposureTime / 1000)); strcpy(extimeunit, (captureResult.exposureTime >= 1000000) ? "ms" : "ns"); diff --git a/app/src/main/cpp/camera2/ndkcamera.cpp b/app/src/main/cpp/camera2/ndkcamera.cpp index 9a0b4711..32d69899 100644 --- a/app/src/main/cpp/camera2/ndkcamera.cpp +++ b/app/src/main/cpp/camera2/ndkcamera.cpp @@ -847,20 +847,17 @@ void NdkCamera::onImageAvailable(AImageReader* reader) // int y_len = 0; int u_len = 0; int v_len = 0; - if (y_data == 0) - { - AImage_getPlaneData(image, 0, &y_data, &y_len); - } + AImage_getPlaneData(image, 0, &y_data, &y_len); AImage_getPlaneData(image, 1, &u_data, &u_len); AImage_getPlaneData(image, 2, &v_data, &v_len); -#if 0 +#if 1 #if __cplusplus >= 201703L - uint64_t avgy = std::reduce(y_data, y_data + y_len, 0); + uint64_t avgY = std::reduce(y_data, y_data + y_len, 0); #else - uint64_t avgy = std::accumulate(y_data, y_data + y_len, 0); + uint64_t avgY = std::accumulate(y_data, y_data + y_len, 0); #endif - mResult.avgY = avgy / y_len; + mResult.avgY = avgY / y_len; #endif if (u_data == v_data + 1 && v_data == y_data + width * height && y_pixelStride == 1 && u_pixelStride == 2 && v_pixelStride == 2 && y_rowStride == width && u_rowStride == width && v_rowStride == width)