17 map<int,Ptr<VideoWriter> > obj_;
21 (
"Quality", cv::VIDEOWRITER_PROP_QUALITY)
22 (
"FrameBytes", cv::VIDEOWRITER_PROP_FRAMEBYTES)
23 (
"NStripes", cv::VIDEOWRITER_PROP_NSTRIPES);
39 OptionsParser(vector<MxArray>::const_iterator first,
40 vector<MxArray>::const_iterator last)
41 : fourcc(CV_FOURCC(
'U',
'2',
'6',
'3')),
45 nargchk(((last-first) % 2) == 0);
46 for (; first != last; first += 2) {
47 string key((*first).toString());
48 const MxArray& val = *(first + 1);
49 if (key ==
"FourCC") {
50 if (val.isChar() && val.numel()==4) {
51 string cc(val.toString());
52 fourcc = VideoWriter::fourcc(cc[0], cc[1], cc[2], cc[3]);
57 else if (key ==
"FPS")
59 else if (key ==
"Color")
60 isColor = val.toBool();
62 mexErrMsgIdAndTxt(
"mexopencv:error",
63 "Unrecognized option %s", key.c_str());
76 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
82 vector<MxArray> rhs(prhs, prhs+nrhs);
83 int id = rhs[0].toInt();
84 string method(rhs[1].toString());
87 if (method ==
"new") {
89 obj_[++last_id] = makePtr<VideoWriter>();
95 Ptr<VideoWriter> obj = obj_[id];
96 if (method ==
"delete") {
100 else if (method ==
"open") {
102 string filename(rhs[2].toString());
103 Size frameSize(rhs[3].toSize());
104 OptionsParser opts(rhs.begin() + 4, rhs.end());
105 bool b = obj->open(filename, opts.fourcc, opts.fps, frameSize,
109 else if (method ==
"isOpened") {
111 bool b = obj->isOpened();
114 else if (method ==
"release") {
118 else if (method ==
"write") {
119 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
121 for (
int i=3; i<nrhs; i+=2) {
122 string key(rhs[i].toString());
123 if (key ==
"FlipChannels")
124 flip = rhs[i+1].toBool();
126 mexErrMsgIdAndTxt(
"mexopencv:error",
127 "Unrecognized option %s", key.c_str());
129 Mat frame(rhs[2].toMat());
130 if (flip && frame.channels() == 3)
131 cvtColor(frame, frame, cv::COLOR_RGB2BGR);
134 else if (method ==
"get") {
136 string prop(rhs[2].toString());
137 double value = obj->get(VidWriterProp[prop]);
140 else if (method ==
"set") {
142 string prop(rhs[2].toString());
143 double value = rhs[3].toDouble();
144 bool success = obj->set(VidWriterProp[prop], value);
146 mexWarnMsgIdAndTxt(
"mexopencv:error",
147 "Error setting property %s", prop.c_str());
150 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized operation");
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.