33 for (; first != last; first += 2) {
34 string key(first->toString());
35 const MxArray& val = *(first + 1);
36 if (key ==
"ThresholdON")
38 else if (key ==
"ThresholdOFF")
40 else if (key ==
"LocalEnergyTemporalConstant")
42 else if (key ==
"LocalEnergySpatialConstant")
44 else if (key ==
"NeighborhoodEnergyTemporalConstant")
46 else if (key ==
"NeighborhoodEnergySpatialConstant")
48 else if (key ==
"ContextEnergyTemporalConstant")
50 else if (key ==
"ContextEnergySpatialConstant")
54 "Unrecognized option %s", key.c_str());
64 const char *fields[] = {
"ThresholdON",
"ThresholdOFF",
65 "LocalEnergyTemporalConstant",
"LocalEnergySpatialConstant",
66 "NeighborhoodEnergyTemporalConstant",
67 "NeighborhoodEnergySpatialConstant",
"ContextEnergyTemporalConstant",
68 "ContextEnergySpatialConstant"};
96 int id = rhs[0].toInt();
97 string method(rhs[1].toString());
100 if (method ==
"new") {
113 if (method ==
"delete") {
118 else if (method ==
"clear") {
122 else if (method ==
"load") {
123 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
125 bool loadFromString =
false;
126 for (
int i=3; i<nrhs; i+=2) {
127 string key(rhs[i].toString());
128 if (key ==
"ObjName")
129 objname = rhs[i+1].toString();
130 else if (key ==
"FromString")
131 loadFromString = rhs[i+1].toBool();
134 "Unrecognized option %s", key.
c_str());
143 FileStorage fs(rhs[2].toString(), FileStorage::READ +
144 (loadFromString ? FileStorage::MEMORY : 0));
153 else if (method ==
"save") {
155 obj->
save(rhs[2].toString());
157 else if (method ==
"empty") {
161 else if (method ==
"getDefaultName") {
165 else if (method ==
"getSize") {
169 else if (method ==
"setup") {
170 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
171 string segmentationParameterFile(rhs[2].toString());
172 bool applyDefaultSetupOnFailure =
true;
173 for (
int i=3; i<nrhs; i+=2) {
174 string key(rhs[i].toString());
175 if (key ==
"ApplyDefaultSetupOnFailure")
176 applyDefaultSetupOnFailure = rhs[i+1].toBool();
179 "Unrecognized option %s", key.
c_str());
181 obj->
setup(segmentationParameterFile, applyDefaultSetupOnFailure);
183 else if (method ==
"setupParameters") {
187 obj->
setup(newParameters);
189 else if (method ==
"getParameters") {
193 else if (method ==
"printSetup") {
197 else if (method ==
"write") {
199 string fname(rhs[2].toString());
201 FileStorage fs(fname, FileStorage::WRITE + FileStorage::MEMORY);
210 else if (method ==
"run") {
211 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
212 int channelIndex = 0;
213 for (
int i=3; i<nrhs; i+=2) {
214 string key(rhs[i].toString());
215 if (key ==
"ChannelIndex")
216 channelIndex = rhs[i+1].toInt();
219 "Unrecognized option %s", key.
c_str());
222 obj->
run(inputToSegment, channelIndex);
224 else if (method ==
"getSegmentationPicture") {
228 plhs[0] =
MxArray(transientAreas);
230 else if (method ==
"clearAllBuffers") {
236 "Unrecognized operation %s", method.
c_str());
MxArray toStruct(const SegmentationParameters ¶ms)
Convert segmentation parameters to scalar struct.
virtual const String printSetup()=0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual void clearAllBuffers()=0
virtual bool isOpened() const
virtual void run(InputArray inputToSegment, const int channelIndex=0)=0
virtual void setup(String segmentationParameterFile="", const bool applyDefaultSetupOnFailure=true)=0
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
void createSegmentationParameters(SegmentationParameters ¶ms, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of SegmentationParameters using options in arguments.
float neighborhoodEnergy_temporalConstant
map< int, Ptr< TransientAreasSegmentationModule > > obj_
Object container.
virtual String releaseAndGetString()
virtual void read(const FileNode &fn)
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
float neighborhoodEnergy_spatialConstant
float contextEnergy_spatialConstant
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
int last_id
Last object id to allocate.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
FileNode getFirstTopLevelNode() const
float localEnergy_temporalConstant
virtual String getDefaultName() const
Global constant definitions.
virtual void write(String fs) const=0
virtual SegmentationParameters getParameters()=0
float localEnergy_spatialConstant
virtual void save(const String &filename) const
virtual bool empty() const
virtual void getSegmentationPicture(OutputArray transientAreas)=0
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
float contextEnergy_temporalConstant