3

I would like to know how to make function to do high dynamic range imaging with swift 4.2

I make function in OpenCVWrapper.h :

+(UIImage *) hdrImaging:(NSArray *)images :(NSArray *)times;

the first question is how to set vectors in params instead of array?

after I have my OpenCVWrapper.mm file where I make the function:

#import <opencv2/opencv.hpp>
#import "OpenCVWrapper.h"
#import <UIKit/UIKit.h>
#include <opencv2/photo.hpp>
#include <opencv2/highgui/ios.h>

@implementation OpenCVWrapper

+(UIImage *) hdrImaging:(/* HERE PUT VECTOR PARAMS */)images :(/* HERE PUT VECTOR PARAMS */)times{

    Mat response; 
    //here to declare Mat it's cv::Mat response;

    //I don't know how to declare and use Ptr function and what file import to use this function
    Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
    calibrate->process(images, response, times);


    Mat hdr;
    Ptr<MergeDebevec> merge_debevec = createMergeDebevec();
    merge_debevec->process(images, hdr, times, response);
    Mat ldr;
    Ptr<TonemapDurand> tonemap = createTonemapDurand(2.2f);
    tonemap->process(hdr, ldr);
    Mat fusion;
    Ptr<MergeMertens> merge_mertens = createMergeMertens();
    merge_mertens->process(images, fusion);

    response = fusion * 255;

    return MatToUIImage(response);
}

@end

Can someone help me to make this function in m'y .mm file, how to pass vector params in the function and what file import for this code run ?

thanks !

1 Answer 1

1

To answer your question:-

  • You could use "std::vector<std::vector<cv::Point> >" type for your function parameters in case of contours or use "std::vector<cv::Point2f>" for points. There are other types too but I didn't use anything more on my project

  • Make sure to include "#import<opencv2/imgcodecs/ios.h>" to your header

  • Use 'cv::Mat' instead of 'Mat' and try prefixing 'cv::' before most of the unrecognised types and functions as well(This mostly works 😂)

Here's how your function should probably be like (Tested and has no errors):-

+(UIImage *) hdrImaging:(std::vector<std::vector<cv::Point> >)images :(std::vector<std::vector<cv::Point> >)times{

cv::Mat response;   

cv::Ptr<cv::CalibrateDebevec> calibrate = cv::createCalibrateDebevec();
calibrate->process(images, response, times);


cv::Mat hdr;
cv::Ptr<cv::MergeDebevec> merge_debevec = cv::createMergeDebevec();
merge_debevec->process(images, hdr, times, response);
cv::Mat ldr;
cv::Ptr<cv::TonemapDurand> tonemap = cv::createTonemapDurand(2.2f);
tonemap->process(hdr, ldr);
cv::Mat fusion;
cv::Ptr<cv::MergeMertens> merge_mertens = cv::createMergeMertens();
merge_mertens->process(images, fusion);

response = fusion * 255;

return MatToUIImage(response);

}

Make sure you change your parameter type to something that matches your use case, as I'm just giving an example

Hope this helps!

Sign up to request clarification or add additional context in comments.

9 Comments

thanks for your answer, with 'cv::Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();' I have the following error: - C++ requires a type specifier for all declarations - Use of undeclared identifier 'CalibrateDebevec' - Use of undeclared identifier 'createCalibrateDebevec'
and #import <opencv2/imgcodecs/ios.h> ---> #import <opencv2/imgcodecs/ios.h>
Seems like the header file that I shared is available only in recent OpenCV libraries. I have used the pod and it works fine for me.
Glad it helped! And, this error is due to memory issues, and mostly occurs when you have a ton of instances that overload the memory causing an exception. There is no particular fix for this unless you know the source that causes it. Hence suggest you to understand what your code does here and take measures accordingly
Thank you very much @Lok SN your help save me !
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.