19 map<int,Ptr<TwoPassStabilizer> > obj_;
29 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
35 vector<MxArray> rhs(prhs, prhs+nrhs);
36 int id = rhs[0].toInt();
37 string method(rhs[1].toString());
40 if (method ==
"new") {
42 obj_[++last_id] = makePtr<TwoPassStabilizer>();
47 else if (method ==
"RansacParamsDefault2dMotion") {
50 RansacParams ransacParams = RansacParams::default2dMotion(model);
56 Ptr<TwoPassStabilizer> obj = obj_[id];
57 if (method ==
"delete") {
61 else if (method ==
"reset") {
65 else if (method ==
"nextFrame") {
66 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
68 for (
int i=2; i<nrhs; i+=2) {
69 string key(rhs[i].toString());
70 if (key ==
"FlipChannels")
71 flip = rhs[i+1].toBool();
73 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
75 Mat frame = obj->nextFrame();
76 if (flip && (frame.channels() == 3 || frame.channels() == 4)) {
78 cvtColor(frame, frame, (frame.channels()==3 ?
79 cv::COLOR_BGR2RGB : cv::COLOR_BGRA2RGBA));
83 else if (method ==
"setLog") {
88 else if (method ==
"setFrameSource") {
91 rhs[2].toString(), rhs.begin() + 3, rhs.end());
92 obj->setFrameSource(p);
94 else if (method ==
"setDeblurer") {
97 rhs[2].toString(), rhs.begin() + 3, rhs.end());
100 else if (method ==
"setMotionEstimator") {
103 rhs[2].toString(), rhs.begin() + 3, rhs.end());
104 obj->setMotionEstimator(p);
106 else if (method ==
"setInpainter") {
109 rhs[2].toString(), rhs.begin() + 3, rhs.end());
110 obj->setInpainter(p);
112 else if (method ==
"setMotionStabilizer") {
115 rhs[2].toString(), rhs.begin() + 3, rhs.end());
116 obj->setMotionStabilizer(p);
118 else if (method ==
"setWobbleSuppressor") {
121 rhs[2].toString(), rhs.begin() + 3, rhs.end());
122 obj->setWobbleSuppressor(p);
124 else if (method ==
"getLog") {
126 Ptr<ILog> p = obj->log();
129 else if (method ==
"getFrameSource") {
131 Ptr<IFrameSource> p = obj->frameSource();
134 else if (method ==
"getDeblurer") {
136 Ptr<DeblurerBase> p = obj->deblurrer();
139 else if (method ==
"getMotionEstimator") {
141 Ptr<ImageMotionEstimatorBase> p = obj->motionEstimator();
144 else if (method ==
"getInpainter") {
146 Ptr<InpainterBase> p = obj->inpainter();
149 else if (method ==
"getMotionStabilizer") {
151 Ptr<IMotionStabilizer> p = obj->motionStabilizer();
154 else if (method ==
"getWobbleSuppressor") {
156 Ptr<WobbleSuppressorBase> p = obj->wobbleSuppressor();
159 else if (method ==
"get") {
161 string prop(rhs[2].toString());
162 if (prop ==
"BorderMode")
164 else if (prop ==
"CorrectionForInclusion")
165 plhs[0] =
MxArray(obj->doCorrectionForInclusion());
166 else if (prop ==
"Radius")
167 plhs[0] =
MxArray(obj->radius());
168 else if (prop ==
"TrimRatio")
169 plhs[0] =
MxArray(obj->trimRatio());
170 else if (prop ==
"EstimateTrimRatio")
171 plhs[0] =
MxArray(obj->mustEstimateTrimaRatio());
173 mexErrMsgIdAndTxt(
"mexopencv:error",
174 "Unrecognized property %s", prop.c_str());
176 else if (method ==
"set") {
178 string prop(rhs[2].toString());
179 if (prop ==
"BorderMode")
180 obj->setBorderMode(
BorderType[rhs[3].toString()]);
181 else if (prop ==
"CorrectionForInclusion")
182 obj->setCorrectionForInclusion(rhs[3].toBool());
183 else if (prop ==
"Radius")
184 obj->setRadius(rhs[3].toInt());
185 else if (prop ==
"TrimRatio")
186 obj->setTrimRatio(rhs[3].toFloat());
187 else if (prop ==
"EstimateTrimRatio")
188 obj->setEstimateTrimRatio(rhs[3].toBool());
190 mexErrMsgIdAndTxt(
"mexopencv:error",
191 "Unrecognized property %s", prop.c_str());
194 mexErrMsgIdAndTxt(
"mexopencv:error",
195 "Unrecognized operation %s", method.c_str());
Common definitions for the videostab module.
cv::Ptr< cv::videostab::DeblurerBase > createDeblurerBase(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of DeblurerBase using options in arguments.
cv::Ptr< cv::videostab::InpainterBase > createInpainterBase(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of InpainterBase using options in arguments.
cv::Ptr< cv::videostab::IMotionStabilizer > createIMotionStabilizer(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of IMotionStabilizer using options in arguments.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
MxArray toStruct(const std::vector< cv::ml::DTrees::Node > &nodes)
Convert tree nodes to struct array.
const ConstMap< int, std::string > BorderTypeInv
Inverse border type map for option processing.
cv::Ptr< cv::videostab::WobbleSuppressorBase > createWobbleSuppressorBase(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of WobbleSuppressorBase using options in arguments.
const ConstMap< std::string, int > BorderType
Border type map for option processing.
const ConstMap< std::string, cv::videostab::MotionModel > MotionModelMap
motion model types for option processing
cv::Ptr< cv::videostab::IFrameSource > createIFrameSource(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of IFrameSource using options in arguments.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
cv::Ptr< cv::videostab::ImageMotionEstimatorBase > createImageMotionEstimator(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of ImageMotionEstimatorBase using options in arguments.
cv::Ptr< cv::videostab::ILog > createILog(const std::string &type)
Create an instance of ILog of the specified type.