gocv
gocv copied to clipboard
Better error handling
It seems like a CVError or cv::Exception shuts down the program. This is inconvenient if gocv is run in a web server because the server is unable to handle other requests.
For example, gocv.AddWeighted(decodedImage1, request.Alpha, decodedImage2, 1-request.Alpha, 0.0, &result)
will cause the program to shut down if images are not of the same size
is there a way to implement better error handling ? I can contribute.
Please see this previous issue https://github.com/hybridgroup/gocv/issues/186 related to Go issue https://github.com/golang/go/issues/13672 discussing. Seems like Windows exception handling is the obstacle here.
Can this be a potential solution ? https://artem.krylysov.com/blog/2017/04/13/handling-cpp-exceptions-in-go/
Hello @zak905 this does not work on Windows, which is why we have not added to GoCV so far.
It definitely needs a solution, even if it doesn't work on Windows.
I found a solution on Windows that works with mingw. Any suggestions on how to incorporate this to the entire library?
#include <windows.h>
LONG WINAPI
VectoredHandlerSkip(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
PCONTEXT Context;
Context = ExceptionInfo->ContextRecord;
#ifdef _AMD64_
Context->Rip++;
#else
Context->Eip++;
#endif
return EXCEPTION_EXECUTE_HANDLER;
}
double FindTransformECC(Mat templateImage, Mat inputImage, Mat warpMatrix, int motionType, TermCriteria criteria, Mat inputMask, int gaussFiltSize){
auto handle = AddVectoredExceptionHandler(1, VectoredHandlerSkip);
double res;
try {
res = cv::findTransformECC(*templateImage, *inputImage, *warpMatrix, motionType, *criteria, *inputMask, gaussFiltSize);
} catch(std::exception &e) {
res = -1;
}
RemoveVectoredExceptionHandler(handle);
return res;
}