1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 //#include "qfrontend.h"
50 // uncomment this function
51 // if you wish that CV reports errors to Matlab and don't terminate programm
53 //------------- Error function ----------------------------------------------------------
54 char cvErrorMessage[1000]; // error message from some OpenCV function
58 CVStatus GuiBoxReport_NotFatal( CVStatus status, const char *funcName,
59 const char *context, const char *file, int line)
63 const char* errText = cvErrorStr( status );
65 if ( cvGetErrMode() != CV_ErrModeSilent )
67 if ( !funcName ) funcName = "<unknown>";
68 if ( !context ) context = "";
69 if ( !file ) file = "";
70 if ( line < 0 ) line = 0;
73 if ( status == CV_StsBackTrace)
74 sprintf(mess,"Called from %s(): [file %s, line %d]\n%s\n%s\n(status:%d)\n",
75 funcName, file,line,context, errText, status);
76 else if ( status == CV_StsAutoTrace )
77 sprintf(mess,"Called from %s(): [file %s, line %d]\n%s\n%s\n(status:%d)\n",
78 funcName, file, line, context, errText, status);
80 sprintf(mess,"In function %s(): [file %s, line %d]\n%s\n%s\n(status:%d)\n",
81 funcName, file, line, context, errText, status);
83 sprintf(cvErrorMessage,"OpenCV Beta 1: %s\n%s",cvErrorStr(cvGetErrStatus()),mess);
90 //-------------------------------------------------------------------------------------
92 //------------- Wrappers --------------------------------------------------------------
96 #include "wrappers.cpp"
99 // you should better to add all names of wrapper functions in map!
101 MapEntry function_map[] =
103 { "Erode" , (void*) wrErode },
104 { "Dilate" , (void*) wrDilate },
105 { "PyrUp" , (void*) wrPyrUp },
106 { "PyrDown" , (void*) wrPyrDown },
107 { "Laplace" , (void*) wrLaplace },
108 { "Sobel" , (void*) wrSobel },
109 { "DistTransform" , (void*) wrDistTransform },
110 { "Canny" , (void*) wrCanny },
111 { "PreCornerDetect" , (void*) wrPreCornerDetect },
112 { "MatchTemplate" , (void*) wrMatchTemplate },
113 { "UpdateMotionHistory" , (void*) wrUpdateMotionHistory },
114 { "MinMaxLoc" , (void *) wrMinMaxLoc },
115 { "Threshold" , (void *)wrThreshold },
116 { "AdaptiveThreshold" , (void*) wrAdaptiveThreshold },
117 { "FindContours" , (void *)wrFindContours },
118 { "DrawContours" , (void *)wrDrawContours },
119 { "ApproxPoly" , (void *)wrApproxPoly },
120 { "ContourPerimeter" , (void *)wrContourPerimeter },
121 { "ContourArea" , (void *)wrContourArea },
122 { "FloodFill", (void *)wrFloodFill },
123 { "CalcOpticalFlowPyrLK", (void *)wrCalcOpticalFlowPyrLK },
124 { "GoodFeaturesToTrack", (void *)wrGoodFeaturesToTrack },
127 //-------------------------------------------------------------------------------------
131 void mexFunction( int nlhs, mxArray* plhs[],
132 int nrhs, const mxArray* prhs[] ) {
133 // uncomment these two calls
134 // if you wish that CV report errors to Matlab and don't terminate programm
136 cvRedirectError( GuiBoxReport_NotFatal );
137 cvSetErrMode( CV_ErrModeParent );
142 throw_error( "Internal wrapper error: main function must have more than one argument" );
144 if( !mxIsChar( prhs[0] ) )
145 throw_error( "Internal wrapper error: in main function zero argument must be string" );
147 std::string funcname = get_string( prhs[0] );
149 InitHashTable((MapEntry *)&function_map);
150 MapEntry* entry = FindMapEntry(funcname.c_str());
152 // if wrapper exist we call it
155 void (*pfun) (int nlhs, mxArray* plhs[],int nrhs, const mxArray* prhs[])
156 = (void (__cdecl *)(int nlhs, mxArray* plhs[],
157 int nrhs, const mxArray* prhs[]))(entry->image);
159 (*pfun)(nlhs, plhs, nrhs, prhs);
162 std::ostringstream ostr;
163 ostr << "Internal wrapper error: "<< funcname << " function not found";
164 throw_error( ostr.str() );
170 mexErrMsgTxt( e.get_error_messages() );
174 mexErrMsgTxt( "Unknown C++ exception occurred" );