夜视优化

TempBranch
Matthew 9 months ago
parent 1fdbc1701e
commit 6bbf1b6195

@ -48,7 +48,7 @@ add_definitions(-DENABLE_3V3_ALWAYS)
project("microphoto") project("microphoto")
find_package(OpenCV REQUIRED core imgproc highgui) find_package(OpenCV REQUIRED core imgproc highgui photo)
# find_package(OpenCV REQUIRED core imgproc) # find_package(OpenCV REQUIRED core imgproc)
if(OpenCV_FOUND) if(OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS}) include_directories(${OpenCV_INCLUDE_DIRS})

@ -750,9 +750,13 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished(
res = AndroidBitmap_lockPixels(env, bitmap, &pixels); res = AndroidBitmap_lockPixels(env, bitmap, &pixels);
cv::Mat tmp(info.height, info.width, CV_8UC4, 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); // 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); AndroidBitmap_unlockPixels(env, bitmap);

@ -1719,30 +1719,41 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
#ifdef OUTPUT_CAMERA_DBG_INFO #ifdef OUTPUT_CAMERA_DBG_INFO
bool shouldRetry = false; bool shouldRetry = false;
#if 0 if (mCamera != NULL) {
NdkCamera::CAPTURE_RESULT captureResult = mCamera->getCaptureResult();
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 (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 #endif // OUTPUT_CAMERA_DBG_INFO
if (!std::filesystem::exists(std::filesystem::path(fullPath))) if (!std::filesystem::exists(std::filesystem::path(fullPath)))

@ -415,6 +415,7 @@ public class MicroPhotoService extends Service {
@Override @Override
public void onHeaderDecoded(@NonNull ImageDecoder decoder, @NonNull ImageDecoder.ImageInfo info, @NonNull ImageDecoder.Source source) { public void onHeaderDecoded(@NonNull ImageDecoder decoder, @NonNull ImageDecoder.ImageInfo info, @NonNull ImageDecoder.Source source) {
decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE); decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE);
decoder.setTargetSize(info.getSize().getWidth(), info.getSize().getHeight());
} }
}; };

@ -176,6 +176,8 @@ public class RawActivity extends AppCompatActivity {
public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
configureTransform(width, height); configureTransform(width, height);
MicroPhotoService.infoLog("RawActivity onSurfaceTextureAvailable PHOTOID=" + Long.toString(mPhotoId));
if (!mTaken) { if (!mTaken) {
mTaken = true; mTaken = true;
@ -192,6 +194,8 @@ public class RawActivity extends AppCompatActivity {
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {
configureTransform(width, height); configureTransform(width, height);
MicroPhotoService.infoLog("RawActivity onSurfaceTextureSizeChanged PHOTOID=" + Long.toString(mPhotoId));
if (!mTaken) { if (!mTaken) {
mTaken = true; mTaken = true;
@ -262,8 +266,6 @@ public class RawActivity extends AppCompatActivity {
private int mOrientation = -1; private int mOrientation = -1;
/** /**
* A {@link CameraCaptureSession } for camera preview. * A {@link CameraCaptureSession } for camera preview.
*/ */
@ -389,7 +391,6 @@ public class RawActivity extends AppCompatActivity {
broadcastPhotoFile(false, ""); broadcastPhotoFile(false, "");
finish(); finish();
} }
}; };
/** /**
@ -643,6 +644,9 @@ public class RawActivity extends AppCompatActivity {
// configure the preview bounds here (otherwise, we wait until the surface is ready in // configure the preview bounds here (otherwise, we wait until the surface is ready in
// the SurfaceTextureListener). // the SurfaceTextureListener).
if (mTextureView.isAvailable()) { if (mTextureView.isAvailable()) {
MicroPhotoService.infoLog("RawActivity mTextureView is Available PHOTOID=" + Long.toString(mPhotoId));
configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
mMessageHandler.postDelayed(new Runnable() { mMessageHandler.postDelayed(new Runnable() {
@ -1354,10 +1358,9 @@ public class RawActivity extends AppCompatActivity {
DngCreator dngCreator = new DngCreator(mCharacteristics, mCaptureResult); DngCreator dngCreator = new DngCreator(mCharacteristics, mCaptureResult);
FileOutputStream output = null; FileOutputStream output = null;
try { try {
MicroPhotoService.infoLog("RawActivity Image Size=" + Integer.toString(mImage.getWidth()) + "," + Integer.toString(mImage.getHeight()));
output = new FileOutputStream(mFile); output = new FileOutputStream(mFile);
dngCreator.writeImage(output, mImage); dngCreator.writeImage(output, mImage);
mResult = true; mResult = true;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

Loading…
Cancel
Save