26 string method(rhs[0].toString());
28 if (method ==
"from2points") {
30 if (rhs[1].isNumeric() && rhs[1].numel() == 2 &&
31 rhs[2].isNumeric() && rhs[2].numel() == 2) {
32 Point2d pt1(rhs[1].toPoint_<double>()),
33 pt2(rhs[2].toPoint_<double>());
39 pts2(rhs[2].toVector<Point2d>());
40 if (pts1.size() != pts2.
size())
44 for (
size_t i = 0; i < pts1.size(); ++i)
46 plhs[0] = (rhs[1].isCell() && rhs[2].isCell()) ?
50 else if (method ==
"tl") {
52 if (rhs[1].isNumeric() && rhs[1].numel() == 4) {
53 Rect2d rect(rhs[1].toRect_<double>());
61 for (
size_t i = 0; i < rects.
size(); ++i)
63 plhs[0] = (rhs[1].isCell()) ?
67 else if (method ==
"br") {
69 if (rhs[1].isNumeric() && rhs[1].numel() == 4) {
70 Rect2d rect(rhs[1].toRect_<double>());
78 for (
size_t i = 0; i < rects.
size(); ++i)
80 plhs[0] = (rhs[1].isCell()) ?
84 else if (method ==
"size") {
86 if (rhs[1].isNumeric() && rhs[1].numel() == 4) {
87 Rect2d rect(rhs[1].toRect_<double>());
95 for (
size_t i = 0; i < rects.
size(); ++i)
97 plhs[0] = (rhs[1].isCell()) ?
101 else if (method ==
"area") {
103 if (rhs[1].isNumeric() && rhs[1].numel() == 4) {
104 Rect2d rect(rhs[1].toRect_<double>());
105 double a = rect.
area();
112 for (
size_t i = 0; i < rects.
size(); ++i)
117 else if (method ==
"contains") {
119 Rect2d rect(rhs[1].toRect_<double>());
120 if (rhs[2].isNumeric() && rhs[2].numel() == 2) {
121 Point2d pt(rhs[2].toPoint_<double>());
128 for (
size_t i = 0; i < pts.
size(); ++i)
133 else if (method ==
"adjustPosition") {
135 if (rhs[1].isNumeric() && rhs[1].numel() == 4 &&
136 rhs[2].isNumeric() && rhs[2].numel() == 2) {
137 Rect2d rect(rhs[1].toRect_<double>());
138 Point2d pt(rhs[2].toPoint_<double>());
144 if (rhs[2].isNumeric() && rhs[2].numel() == 2) {
145 Point2d pt(rhs[2].toPoint_<double>());
146 for (
size_t i = 0; i < rects.
size(); ++i)
153 for (
size_t i = 0; i < rects.
size(); ++i)
156 plhs[0] = (rhs[1].isCell()) ?
160 else if (method ==
"adjustSize") {
162 if (rhs[1].isNumeric() && rhs[1].numel() == 4 &&
163 rhs[2].isNumeric() && rhs[2].numel() == 2) {
164 Rect2d rect(rhs[1].toRect_<double>());
165 Size2d sz(rhs[2].toSize_<double>());
171 if (rhs[2].isNumeric() && rhs[2].numel() == 2) {
172 Size2d sz(rhs[2].toSize_<double>());
173 for (
size_t i = 0; i < rects.
size(); ++i)
180 for (
size_t i = 0; i < rects.
size(); ++i)
183 plhs[0] = (rhs[1].isCell()) ?
187 else if (method ==
"intersect") {
189 if (rhs[1].isNumeric() && rhs[1].numel() == 4 &&
190 rhs[2].isNumeric() && rhs[2].numel() == 4) {
191 Rect2d rect1(rhs[1].toRect_<double>()),
192 rect2(rhs[2].toRect_<double>());
198 if (rhs[2].isNumeric() && rhs[2].numel() == 4) {
199 Rect2d rect2(rhs[2].toRect_<double>());
200 for (
size_t i = 0; i < rects1.
size(); ++i)
207 for (
size_t i = 0; i < rects1.
size(); ++i)
208 rects1[i] &= rects2[i];
210 plhs[0] = (rhs[1].isCell()) ?
214 else if (method ==
"union") {
216 if (rhs[1].isNumeric() && rhs[1].numel() == 4 &&
217 rhs[2].isNumeric() && rhs[2].numel() == 4) {
218 Rect2d rect1(rhs[1].toRect_<double>()),
219 rect2(rhs[2].toRect_<double>());
225 if (rhs[2].isNumeric() && rhs[2].numel() == 4) {
226 Rect2d rect2(rhs[2].toRect_<double>());
227 for (
size_t i = 0; i < rects1.
size(); ++i)
234 for (
size_t i = 0; i < rects1.
size(); ++i)
235 rects1[i] |= rects2[i];
237 plhs[0] = (rhs[1].isCell()) ?
241 else if (method ==
"crop") {
242 nargchk((nrhs==3 || nrhs==4) && nlhs<=1);
244 Rect rect(rhs[2].toRect());
261 "Unrecognized operation %s", method.
c_str());
void copyTo(OutputArray m) const
struct mxArray_tag mxArray
Forward declaration for mxArray.
bool contains(const Point_< _Tp > &pt) const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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...
Size_< _Tp > size() const
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
Global constant definitions.