17 map<int,Ptr<VideoCapture> > obj_;
21 (
"PosMsec", cv::CAP_PROP_POS_MSEC)
22 (
"PosFrames", cv::CAP_PROP_POS_FRAMES)
23 (
"PosAviRatio", cv::CAP_PROP_POS_AVI_RATIO)
24 (
"FrameWidth", cv::CAP_PROP_FRAME_WIDTH)
25 (
"FrameHeight", cv::CAP_PROP_FRAME_HEIGHT)
26 (
"FPS", cv::CAP_PROP_FPS)
27 (
"FourCC", cv::CAP_PROP_FOURCC)
28 (
"FrameCount", cv::CAP_PROP_FRAME_COUNT)
29 (
"Format", cv::CAP_PROP_FORMAT)
30 (
"Mode", cv::CAP_PROP_MODE)
31 (
"Brightness", cv::CAP_PROP_BRIGHTNESS)
32 (
"Contrast", cv::CAP_PROP_CONTRAST)
33 (
"Saturation", cv::CAP_PROP_SATURATION)
34 (
"Hue", cv::CAP_PROP_HUE)
35 (
"Gain", cv::CAP_PROP_GAIN)
36 (
"Exposure", cv::CAP_PROP_EXPOSURE)
37 (
"ConvertRGB", cv::CAP_PROP_CONVERT_RGB)
39 (
"Rectification", cv::CAP_PROP_RECTIFICATION)
41 (
"Monochrome", cv::CAP_PROP_MONOCHROME)
42 (
"Sharpness", cv::CAP_PROP_SHARPNESS)
43 (
"AutoExposure", cv::CAP_PROP_AUTO_EXPOSURE)
44 (
"Gamma", cv::CAP_PROP_GAMMA)
45 (
"Temperature", cv::CAP_PROP_TEMPERATURE)
46 (
"Trigger", cv::CAP_PROP_TRIGGER)
47 (
"TriggerDelay", cv::CAP_PROP_TRIGGER_DELAY)
48 (
"Zoom", cv::CAP_PROP_ZOOM)
49 (
"Focus", cv::CAP_PROP_FOCUS)
50 (
"GUID", cv::CAP_PROP_GUID)
51 (
"ISOSpeed", cv::CAP_PROP_ISO_SPEED)
52 (
"Backlight", cv::CAP_PROP_BACKLIGHT)
53 (
"Pan", cv::CAP_PROP_PAN)
54 (
"Tilt", cv::CAP_PROP_TILT)
55 (
"Roll", cv::CAP_PROP_ROLL)
56 (
"Iris", cv::CAP_PROP_IRIS)
57 (
"Settings", cv::CAP_PROP_SETTINGS)
58 (
"Buffersize", cv::CAP_PROP_BUFFERSIZE)
59 (
"Autofocus", cv::CAP_PROP_AUTOFOCUS);
66 (
"V4L2", cv::CAP_V4L2)
67 (
"FireWare", cv::CAP_FIREWARE)
68 (
"FireWire", cv::CAP_FIREWIRE)
69 (
"IEEE1394", cv::CAP_IEEE1394)
70 (
"DC1394", cv::CAP_DC1394)
71 (
"CMU1394", cv::CAP_CMU1394)
72 (
"QuickTime", cv::CAP_QT)
73 (
"Unicap", cv::CAP_UNICAP)
74 (
"DirectShow", cv::CAP_DSHOW)
75 (
"PvAPI", cv::CAP_PVAPI)
76 (
"OpenNI", cv::CAP_OPENNI)
77 (
"OpenNIAsus", cv::CAP_OPENNI_ASUS)
78 (
"Android", cv::CAP_ANDROID)
79 (
"XIMEA", cv::CAP_XIAPI)
80 (
"AVFoundation", cv::CAP_AVFOUNDATION)
81 (
"Giganetix", cv::CAP_GIGANETIX)
82 (
"MediaFoundation", cv::CAP_MSMF)
83 (
"WinRT", cv::CAP_WINRT)
84 (
"IntelPerC", cv::CAP_INTELPERC)
85 (
"OpenNI2", cv::CAP_OPENNI2)
86 (
"OpenNI2Asus", cv::CAP_OPENNI2_ASUS)
87 (
"gPhoto2", cv::CAP_GPHOTO2)
88 (
"GStreamer", cv::CAP_GSTREAMER)
89 (
"FFMPEG", cv::CAP_FFMPEG)
90 (
"Images", cv::CAP_IMAGES);
100 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
106 vector<MxArray> rhs(prhs, prhs+nrhs);
107 int id = rhs[0].toInt();
108 string method(rhs[1].toString());
111 if (method ==
"new") {
112 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
113 int pref = cv::CAP_ANY;
114 for (
int i=3; i<nrhs; i+=2) {
115 string key(rhs[i].toString());
117 pref = CameraApiMap[rhs[i+1].toString()];
119 mexErrMsgIdAndTxt(
"mexopencv:error",
120 "Unrecognized option %s", key.c_str());
122 obj_[++last_id] = (rhs[2].isChar()) ?
123 makePtr<VideoCapture>(rhs[2].toString(), pref) :
124 makePtr<VideoCapture>(rhs[2].toInt() + pref);
130 Ptr<VideoCapture> obj = obj_[id];
131 if (method ==
"delete") {
135 else if (method ==
"open") {
136 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
137 int pref = cv::CAP_ANY;
138 for (
int i=3; i<nrhs; i+=2) {
139 string key(rhs[i].toString());
141 pref = CameraApiMap[rhs[i+1].toString()];
143 mexErrMsgIdAndTxt(
"mexopencv:error",
144 "Unrecognized option %s", key.c_str());
147 bool b = (rhs[2].isChar()) ?
148 obj->open(rhs[2].toString(), pref) :
149 obj->open(rhs[2].toInt() + pref);
152 else if (method ==
"isOpened") {
154 bool b = obj->isOpened();
157 else if (method ==
"release") {
161 else if (method ==
"grab") {
163 bool b = obj->grab();
166 else if (method ==
"retrieve") {
167 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
170 for (
int i=2; i<nrhs; i+=2) {
171 string key(rhs[i].toString());
172 if (key ==
"FlipChannels")
173 flip = rhs[i+1].toBool();
174 else if (key ==
"StreamIdx")
175 idx = rhs[i+1].toInt();
177 mexErrMsgIdAndTxt(
"mexopencv:error",
178 "Unrecognized option %s", key.c_str());
181 bool b = obj->retrieve(image, idx);
182 if (b && flip && image.channels()==3)
183 cvtColor(image, image, cv::COLOR_BGR2RGB);
184 plhs[0] =
MxArray(b ? image : Mat());
186 else if (method ==
"read") {
187 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
189 for (
int i=2; i<nrhs; i+=2) {
190 string key(rhs[i].toString());
191 if (key ==
"FlipChannels")
192 flip = rhs[i+1].toBool();
194 mexErrMsgIdAndTxt(
"mexopencv:error",
195 "Unrecognized option %s", key.c_str());
198 bool b = obj->read(image);
199 if (b && flip && image.channels()==3)
200 cvtColor(image, image, cv::COLOR_BGR2RGB);
201 plhs[0] =
MxArray(b ? image : Mat());
203 else if (method ==
"get") {
205 int prop = (rhs[2].isChar()) ?
206 CapProp[rhs[2].toString()] : rhs[2].toInt();
207 double value = obj->get(prop);
210 else if (method ==
"set") {
212 int prop = (rhs[2].isChar()) ?
213 CapProp[rhs[2].toString()] : rhs[2].toInt();
214 double value = rhs[3].toDouble();
215 bool success = obj->set(prop, value);
217 mexWarnMsgIdAndTxt(
"mexopencv:error",
218 "Error setting property %d", prop);
221 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.