mexopencv  3.4.1
MEX interface for OpenCV library
refineDetectedMarkers.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "mexopencv_aruco.hpp"
10 #include "opencv2/aruco.hpp"
11 using namespace std;
12 using namespace cv;
13 using namespace cv::aruco;
14 
22 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
23 {
24  // Check the number of arguments
25  nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=4);
26 
27  // Argument vector
28  vector<MxArray> rhs(prhs, prhs+nrhs);
29 
30  // Option processing
31  Mat cameraMatrix, distCoeffs;
32  float minRepDistance = 10.0f;
33  float errorCorrectionRate = 3.0f;
34  bool checkAllOrders = true;
36  for (int i=5; i<nrhs; i+=2) {
37  string key(rhs[i].toString());
38  if (key == "CameraMatrix")
39  cameraMatrix = rhs[i+1].toMat(CV_64F);
40  else if (key == "DistCoeffs")
41  distCoeffs = rhs[i+1].toMat(CV_64F);
42  else if (key == "MinRepDistance")
43  minRepDistance = rhs[i+1].toFloat();
44  else if (key == "ErrorCorrectionRate")
45  errorCorrectionRate = rhs[i+1].toFloat();
46  else if (key == "CheckAllOrders")
47  checkAllOrders = rhs[i+1].toBool();
48  else if (key == "DetectorParameters")
49  params = MxArrayToDetectorParameters(rhs[i+1]);
50  else
51  mexErrMsgIdAndTxt("mexopencv:error",
52  "Unrecognized option %s", key.c_str());
53  }
54  if (params.empty())
55  params = DetectorParameters::create();
56 
57  // Process
58  Mat image(rhs[0].toMat(CV_8U));
59  Ptr<Board> board = MxArrayToBoard(rhs[1]);
60  vector<vector<Point2f> > detectedCorners(MxArrayToVectorVectorPoint<float>(rhs[2])),
61  rejectedCorners(MxArrayToVectorVectorPoint<float>(rhs[4]));
62  vector<int> detectedIds(rhs[3].toVector<int>()),
63  recoveredIdxs;
64  refineDetectedMarkers(image, board, detectedCorners, detectedIds,
65  rejectedCorners, cameraMatrix, distCoeffs, minRepDistance,
66  errorCorrectionRate, checkAllOrders,
67  (nlhs==4) ? recoveredIdxs : noArray(), params);
68  plhs[0] = MxArray(detectedCorners);
69  if (nlhs > 1)
70  plhs[1] = MxArray(detectedIds);
71  if (nlhs > 2)
72  plhs[2] = MxArray(rejectedCorners);
73  if (nlhs > 3)
74  plhs[3] = MxArray(recoveredIdxs);
75 }
#define CV_8U
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
Common definitions for the aruco module.
cv::Ptr< cv::aruco::Board > MxArrayToBoard(const MxArray &arr)
Convert MxArray to cv::Ptr<cv::aruco::Board>
InputOutputArray noArray()
#define CV_64F
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...
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
STL class.
bool empty() const
void refineDetectedMarkers(InputArray image, const Ptr< Board > &board, InputOutputArrayOfArrays detectedCorners, InputOutputArray detectedIds, InputOutputArrayOfArrays rejectedCorners, InputArray cameraMatrix=noArray(), InputArray distCoeffs=noArray(), float minRepDistance=10.f, float errorCorrectionRate=3.f, bool checkAllOrders=true, OutputArray recoveredIdxs=noArray(), const Ptr< DetectorParameters > &parameters=DetectorParameters::create())
Global constant definitions.
T c_str(T... args)
cv::Ptr< cv::aruco::DetectorParameters > MxArrayToDetectorParameters(const MxArray &s)
Convert MxArray to cv::Ptr<cv::aruco::DetectorParameters>
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
cv::Mat toMat() const