00001
00002
00003 #ifndef IMAGE_IMAGE_EXCEPTION_HPP
00004 #define IMAGE_IMAGE_EXCEPTION_HPP
00005 #include <opencv/cxcore.h>
00006 #if CV_MAJOR_VERSION*10 + CV_MINOR_VERSION > 21
00007 #include <opencv2/core/core_c.h>
00008 #else
00009 #include <cxcore.h>
00010 #include <cxerror.h>
00011 #endif
00012 #include "kernel/jafarException.hpp"
00013
00014 namespace jafar {
00015
00016 namespace image {
00017
00023 class ImageException : public ::jafar::kernel::Exception {
00024
00025 public:
00026
00030 enum ExceptionId {
00031 INVALID_COLORSPACE_CONVERSION,
00032 OPENCV_ERROR,
00033 NOT_IMPLEMENTED
00034 };
00035
00045 ImageException(ExceptionId id_,
00046 const std::string& message_,
00047 const std::string& file_, int line_) throw();
00048
00049 virtual ~ImageException() throw();
00050
00051 ExceptionId getExceptionId() const throw();
00052
00054 static void enableOpenC_VException() {
00055 cvSetErrMode(CV_ErrModeParent);
00056 cvRedirectError(&SendErrorToJafar, 0, 0);
00057 };
00058
00059 protected:
00060
00061 ExceptionId id;
00062
00063 static std::string exceptionIdToString(ExceptionId id_) throw();
00064
00065 static int SendErrorToJafar (int status,
00066 const char* func_name,
00067 const char* err_msg,
00068 const char* file_name,
00069 int line,
00070 void* )
00071 {
00072 std::stringstream message;
00073 message
00074 << " openCV Error:"
00075 << "\n Status=" << cvErrorStr(status)
00076 << "\n function name=" << (func_name ? func_name : "unknown")
00077 << "\n error message=" << (err_msg ? err_msg : "unknown")
00078 << "\n file_name=" << (file_name ? file_name : "unknown")
00079 << "\n line=" << line
00080 << "\n trace=" << kernel::get_system_trace()
00081 << std::flush;
00082
00083 jafar::kernel::print_system_trace();
00084
00085 cvSetErrStatus( CV_StsOk );
00086
00087
00088 JFR_ERROR(ImageException,ImageException::OPENCV_ERROR,message.str());
00089 return 0;
00090 }
00091
00092 };
00093
00094 }
00095 }
00096
00097 #endif // IMAGE_IMAGE_EXCEPTION_HPP
00098