text: /**
   * @file arcLength.cpp
   * @brief mex interface for cv::arcLength
   * @ingroup imgproc
   * @author Kota Yamaguchi
   * @date 2011
   */
  #include "mexopencv.hpp"
  #include "opencv2/imgproc.hpp"
  using namespace std;
  using namespace cv;
  
  /**
   * Main entry called from Matlab
   * @param nlhs number of left-hand-side arguments
   * @param plhs pointers to mxArrays in the left-hand-side
   * @param nrhs number of right-hand-side arguments
   * @param prhs pointers to mxArrays in the right-hand-side
   */
  void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
  {
      // Check the number of arguments
      nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
  
      // Argument vector
      vector<MxArray> rhs(prhs, prhs+nrhs);
  
      // Option processing
      bool closed = false;
      for (int i=1; i<nrhs; i+=2) {
          string key(rhs[i].toString());
          if (key == "Closed")
              closed = rhs[i+1].toBool();
          else
              mexErrMsgIdAndTxt("mexopencv:error",
                  "Unrecognized option %s", key.c_str());
      }
  
      // Process
      double d = 0;
      if (rhs[0].isNumeric()) {
          Mat curve(rhs[0].toMat(CV_32F));
          d = arcLength(curve, closed);
      }
      else if (rhs[0].isCell()) {
          vector<Point2f> curve(rhs[0].toVector<Point2f>());
          d = arcLength(curve, closed);
      }
      else
          mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
      plhs[0] = MxArray(d);
  }
  