如果当前亮度值低于25,调整曝光时间和ISO后重新拍一张作为对比

serial
Matthew 1 year ago
parent aa598d5f66
commit 33683b22c6

@ -1241,6 +1241,41 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
cv::Scalar scalarRed(0, 0, 255); // red cv::Scalar scalarRed(0, 0, 255); // red
NdkCamera::CAPTURE_RESULT captureResult = mCamera->getCaptureResult(); 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<IDevice::OSD_INFO> 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 }; char extimeunit[4] = { 0 };
unsigned int extime = (captureResult.exposureTime >= 1000000) ? ((unsigned int)(captureResult.exposureTime / 1000000)) : ((unsigned int)(captureResult.exposureTime / 1000)); unsigned int extime = (captureResult.exposureTime >= 1000000) ? ((unsigned int)(captureResult.exposureTime / 1000000)) : ((unsigned int)(captureResult.exposureTime / 1000));
strcpy(extimeunit, (captureResult.exposureTime >= 1000000) ? "ms" : "ns"); strcpy(extimeunit, (captureResult.exposureTime >= 1000000) ? "ms" : "ns");

@ -847,20 +847,17 @@ void NdkCamera::onImageAvailable(AImageReader* reader)
// int y_len = 0; // int y_len = 0;
int u_len = 0; int u_len = 0;
int v_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, 1, &u_data, &u_len);
AImage_getPlaneData(image, 2, &v_data, &v_len); AImage_getPlaneData(image, 2, &v_data, &v_len);
#if 0 #if 1
#if __cplusplus >= 201703L #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 #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 #endif
mResult.avgY = avgy / y_len; mResult.avgY = avgY / y_len;
#endif #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) 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)

Loading…
Cancel
Save