我使用openCV 3.4.3,我想在Java中使用以下脚本,您可以在此处查看源代码:https://docs.opencv.org/3.4/d3/db7/tutorial_hdr_imaging.html并选择Java。
onCreate之前有我的代码:
public List<Mat> images = new ArrayList<>();
public List<Float> times = new ArrayList<>();
设置图片:
String pathNameFile = "file://"+Environment.getExternalStorageDirectory()+"/test_"+date+"_"+pictureNumber+".jpg";
file = new File(pathNameFile);
Mat img = Imgcodecs.imread(pathNameFile);
images.add(img);
和时间:
lastExifExposureTime = result.get(CaptureResult.SENSOR_EXPOSURE_TIME);
double val = (double)lastExifExposureTime / 1000000000.0;
float floatValue = (float) val;
times.add(floatValue);
这是我进行融合的代码:
Mat response = new Mat();
CalibrateDebevec calibrate = Photo.createCalibrateDebevec();
Mat matTimes = new Mat(times.size(), 1, CvType.CV_32F);
float[] arrayTimes = new float[(int) (matTimes.total()*matTimes.channels())];
for (int i = 0; i < times.size(); i++) {
arrayTimes[i] = times.get(i);
}
matTimes.put(0, 0, arrayTimes);
calibrate.process(images, response, matTimes);
Mat hdr = new Mat();
MergeDebevec mergeDebevec = Photo.createMergeDebevec();
mergeDebevec.process(images, hdr, matTimes);
Mat ldr = new Mat();
TonemapDurand tonemap = Photo.createTonemapDurand(2.2f, 4.0f, 1.0f, 2.0f, 2.0f);
tonemap.process(hdr, ldr);
Mat fusion = new Mat();
MergeMertens mergeMertens = Photo.createMergeMertens();
mergeMertens.process(images, fusion);
Core.multiply(fusion, new Scalar(255,255,255), fusion);
Core.multiply(ldr, new Scalar(255,255,255), ldr);
Imgcodecs.imwrite("fusion.png", fusion);
Imgcodecs.imwrite("ldr.png", ldr);
Imgcodecs.imwrite("hdr.hdr", hdr);
System.exit(0);
我不使用loadExposure方法,因为我在拍照时会输入时间和图片值。
有我的错误:
09-27 11:57:22.464 14702-15123/app.hdrtest.com.test_hdr E/cv::error(): OpenCV(3.4.3) Error: Assertion failed (0 < x_points && x_points <= cols) in virtual void cv::CalibrateDebevecImpl::process(cv::InputArrayOfArrays, cv::OutputArray, cv::InputArray), file /build/3_4_pack-android/opencv/modules/photo/src/calibrate.cpp, line 95
09-27 11:57:22.529 14702-15123/app.hdrtest.com.test_hdr E/org.opencv.photo: photo::process_10() caught cv::Exception: OpenCV(3.4.3) /build/3_4_pack-android/opencv/modules/photo/src/calibrate.cpp:95: error: (-215:Assertion failed) 0 < x_points && x_points <= cols in function 'virtual void cv::CalibrateDebevecImpl::process(cv::InputArrayOfArrays, cv::OutputArray, cv::InputArray)'
09-27 11:57:22.535 14702-15123/app.hdrtest.com.test_hdr E/AndroidRuntime: FATAL EXCEPTION: Camera Background
Process: app.hdrtest.com.test_hdr, PID: 14702
CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.3) /build/3_4_pack-android/opencv/modules/photo/src/calibrate.cpp:95: error: (-215:Assertion failed) 0 < x_points && x_points <= cols in function 'virtual void cv::CalibrateDebevecImpl::process(cv::InputArrayOfArrays, cv::OutputArray, cv::InputArray)'
]
at org.opencv.photo.CalibrateCRF.process_0(Native Method)
at org.opencv.photo.CalibrateCRF.process(CalibrateCRF.java:30)
at app.hdrenvisite.com.envisite_hdr.CameraActivity$5.onCaptureCompleted(CameraActivity.java:317)
at java.lang.reflect.Method.invoke(Native Method)
at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
我该怎么做才能解决此问题?
谢谢