Adding photo HDR
HI found that the HDR module has not been implemented yet and its something I need, so I'm attempting to add it. I'm sure I'm missing something here, but this is where I'm at.
Everything compiles fine and is verified by Intellisense, but it crashes when exciting the example code at the bottom.
I'm flying a little blind in that I'm reverse engineering this addition, any help would be appreciated.
Added: photo/photo_HDR.h to OpenCvSharpExtern
CVAPI(cv::Ptr<cv::CalibrateDebevec>*) photo_HDR_createCalibrateDebevec() {
return clone(cv::createCalibrateDebevec());
}
CVAPI(void) photo_HDR_CalibrateDebevecpProcess(cv::CalibrateDebevec *obj, cv::_InputArray ** srcImgs, int srcImgsLength, cv::_OutputArray *frame, float* times)
{
// Build Mat Vector of images
std::vector<cv::_InputArray> srcImgsVec(srcImgsLength);
// Build float Vector of times
std::vector<float> times_vec(srcImgsLength);
for (int i = 0; i < srcImgsLength; i++) {
srcImgsVec[i] = *srcImgs[i];
times_vec[i] = times[i];
}
obj->process(srcImgsVec, *frame, times_vec);
}
Added: PInvoke/NativeMethods_photo_HDR.cs to OpenCvSharp
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr photo_HDR_createCalibrateDebevec();
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void photo_HDR_CalibrateDebevecpProcess(IntPtr obj, IntPtr[] srcImgs, int srcImgsLength, IntPtr frame, float[] times);
Added: Cv2/Cv2_photo_HDR.cs to OpenCvSharp
static partial class Cv2
{
public static void CalibrateDebevec(IEnumerable<InputArray> srcImgs, OutputArray dst, float[] times)
{
if (srcImgs == null)
throw new ArgumentNullException("srcImgs");
if (dst == null)
throw new ArgumentNullException("dst");
dst.ThrowIfNotReady();
IntPtr calDeb = NativeMethods.photo_HDR_createCalibrateDebevec();
IntPtr[] srcImgPtrs = EnumerableEx.SelectPtrs(srcImgs);
NativeMethods.photo_HDR_CalibrateDebevecpProcess(calDeb, srcImgPtrs, srcImgPtrs.Length, dst.CvPtr, times);
dst.Fix();
}
public static void CalibrateDebevec(IEnumerable<Mat> srcImgs, OutputArray dst, float[] times)
{
IEnumerable<InputArray> srcImgsAsArrays = EnumerableEx.Select(srcImgs, m => new InputArray(m));
CalibrateDebevec(srcImgsAsArrays, dst, times);
}
}
C# execution example:
Mat[] images = new Mat[3];
images[0] = Cv2.ImRead(AssetDatabase.GetAssetPath(sourceA), ImreadModes.AnyColor);
images[1] = Cv2.ImRead(AssetDatabase.GetAssetPath(sourceA), ImreadModes.AnyColor);
images[2] = Cv2.ImRead(AssetDatabase.GetAssetPath(sourceA), ImreadModes.AnyColor);
float[] speeds = new float[3];
speeds[0] = shutterSpeedA;
speeds[1] = shutterSpeedB;
speeds[2] = shutterSpeedC;
response = new Mat();
Cv2.CalibrateDebevec(images, response, speeds);
Thanks a lot :+1:
The photo_HDR_createCalibrateDebevec returns cv::Ptr<cv::CalibrateDebevec>*, but the photo_HDR_CalibrateDebevecpProcess's first argument is cv::CalibrateDebevec*. It is expected to occur some exceptions.
I've tried a few variations but am not able to find the right combination.
This is the example I was using to base it on. (This is currently in OpenCvSharp)
CVAPI(cv::Ptr<cv::superres::SuperResolution>*) superres_createSuperResolution_BTVL1()
{
return clone(cv::superres::createSuperResolution_BTVL1());
}
CVAPI(void) superres_SuperResolution_setInput(cv::superres::SuperResolution *obj,
cv::Ptr<cv::superres::FrameSource> *frameSource)
{
obj->setInput(*frameSource);
}
My code ...How would I change this to work?
CVAPI(cv::Ptr<cv::CalibrateDebevec>*) photo_HDR_createCalibrateDebevec() {
return clone(cv::createCalibrateDebevec());
}
CVAPI(void) photo_HDR_CalibrateDebevecpProcess(cv::CalibrateDebevec *obj, cv::_InputArray ** srcImgs,
int srcImgsLength, cv::_OutputArray *dst, float *times)
{
// Build Mat Vector of images
std::vector<cv::_InputArray> srcImgsVec(srcImgsLength);
// Build float Vector of times
std::vector<float> times_vec(srcImgsLength);
for (int i = 0; i < srcImgsLength; i++) {
srcImgsVec[i] = *srcImgs[i];
times_vec[i] = times[i];
}
obj->process(srcImgsVec, *dst, times_vec);
}
and this is the CS for the exposure
static partial class Cv2
{
public static void CalibrateDebevec(IEnumerable<InputArray> srcImgs, OutputArray dst, float[] times)
{
if (srcImgs == null)
throw new ArgumentNullException("srcImgs");
if (dst == null)
throw new ArgumentNullException("dst");
dst.ThrowIfNotReady();
IntPtr calDeb = NativeMethods.photo_HDR_createCalibrateDebevec();
IntPtr[] srcImgPtrs = EnumerableEx.SelectPtrs(srcImgs);
NativeMethods.photo_HDR_CalibrateDebevecpProcess(calDeb, srcImgPtrs,
srcImgPtrs.Length, dst.CvPtr, times);
dst.Fix();
}
public static void CalibrateDebevec(IEnumerable<Mat> srcImgs, OutputArray dst, float[] times)
{
IEnumerable<InputArray> srcImgsAsArrays = EnumerableEx.Select(srcImgs, m => new InputArray(m));
CalibrateDebevec(srcImgsAsArrays, dst, times);
}
}