19 map<int,Ptr<OnePassStabilizer> > 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<OnePassStabilizer>();
47 else if (method ==
"RansacParamsDefault2dMotion") {
50 RansacParams ransacParams = RansacParams::default2dMotion(model);
56 Ptr<OnePassStabilizer> 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 ==
"setMotionFilter") {
115 rhs[2].toString(), rhs.begin() + 3, rhs.end());
116 obj->setMotionFilter(p);
118 else if (method ==
"getLog") {
120 Ptr<ILog> p = obj->log();
123 else if (method ==
"getFrameSource") {
125 Ptr<IFrameSource> p = obj->frameSource();
128 else if (method ==
"getDeblurer") {
130 Ptr<DeblurerBase> p = obj->deblurrer();
133 else if (method ==
"getMotionEstimator") {
135 Ptr<ImageMotionEstimatorBase> p = obj->motionEstimator();
138 else if (method ==
"getInpainter") {
140 Ptr<InpainterBase> p = obj->inpainter();
143 else if (method ==
"getMotionFilter") {
145 Ptr<MotionFilterBase> p = obj->motionFilter();
148 else if (method ==
"get") {
150 string prop(rhs[2].toString());
151 if (prop ==
"BorderMode")
153 else if (prop ==
"CorrectionForInclusion")
154 plhs[0] =
MxArray(obj->doCorrectionForInclusion());
155 else if (prop ==
"Radius")
156 plhs[0] =
MxArray(obj->radius());
157 else if (prop ==
"TrimRatio")
158 plhs[0] =
MxArray(obj->trimRatio());
160 mexErrMsgIdAndTxt(
"mexopencv:error",
161 "Unrecognized property %s", prop.c_str());
163 else if (method ==
"set") {
165 string prop(rhs[2].toString());
166 if (prop ==
"BorderMode")
167 obj->setBorderMode(
BorderType[rhs[3].toString()]);
168 else if (prop ==
"CorrectionForInclusion")
169 obj->setCorrectionForInclusion(rhs[3].toBool());
170 else if (prop ==
"Radius")
171 obj->setRadius(rhs[3].toInt());
172 else if (prop ==
"TrimRatio")
173 obj->setTrimRatio(rhs[3].toFloat());
175 mexErrMsgIdAndTxt(
"mexopencv:error",
176 "Unrecognized property %s", prop.c_str());
179 mexErrMsgIdAndTxt(
"mexopencv:error",
180 "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.
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.
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::MotionFilterBase > createMotionFilterBase(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of MotionFilterBase using options in arguments.
cv::Ptr< cv::videostab::ILog > createILog(const std::string &type)
Create an instance of ILog of the specified type.