MxArray MxArray::at(mwIndex index) const { if (!isCell()) mexErrMsgIdAndTxt("mexopencv:error", "MxArray is not cell"); if (numel() <= index) mexErrMsgIdAndTxt("mexopencv:error", "Index out of range"); return MxArray(mxGetCell(p_, index)); }
MEXFUNCTION_LINKAGE void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nlhs != 1) mexErrMsgTxt("nlhs != 1"); if (nrhs != 2) mexErrMsgTxt("nrhs != 2"); cv::Mat src = MxArray(prhs[0]).toMat(); src.convertTo(src, cv::DataType<float>::type); cv::cvtColor(src, src, CV_BGR2RGB); std::string modelFile = MxArray(prhs[1]).toString(); StructuredEdgeDetection img2edges(modelFile); cv::Mat edges; img2edges.__getFeatures(src, edges); edges.convertTo(edges, cv::DataType<double>::type); plhs[0] = MxArray(edges); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { FImage Im; Im.LoadMatlabImage(prhs[0]); // height * width * channels (in that order) cv::Mat img = MxArray(prhs[0]).toMat(CV_32F); // Convert to single floating point grayscale image int rows = img.rows; int cols = img.cols; int channels = img.channels(); cv::Mat img2, img3; cv::GaussianBlur(img, img2, cv::Size(5, 5), 0.67, 0, cv::BORDER_REPLICATE); int w = (int)ceil(img.cols / 2.0f); int h = (int)ceil(img.rows / 2.0f); cv::resize(img, img3, cv::Size(w, h), 0, 0, cv::INTER_CUBIC); plhs[0] = MxArray(img2); plhs[1] = MxArray(img3); }
MxArray MxArray::at(const std::string& fieldName, mwIndex index) const { if (!isStruct()) mexErrMsgIdAndTxt("mexopencv:error", "MxArray is not struct"); if (numel() <= index) mexErrMsgIdAndTxt("mexopencv:error", "Index out of range"); const mxArray* pm = mxGetField(p_, index, fieldName.c_str()); if (!pm) mexErrMsgIdAndTxt("mexopencv:error", "Field '%s' doesn't exist", fieldName.c_str()); return MxArray(pm); }
std::vector<MxArray> MxArray::toVector() const { if (isCell()) { int n = numel(); std::vector<MxArray> v; v.reserve(n); for (int i = 0; i < n; ++i) v.push_back(MxArray(mxGetCell(p_, i))); return v; } else return std::vector<MxArray>(1, *this); }
std::vector<MxArray> MxArray::toVector() const { std::vector<MxArray> v; if (isCell()) { const mwSize n = numel(); v.reserve(n); for (mwIndex i = 0; i < n; ++i) //v.push_back(at<MxArray>(i)); v.push_back(MxArray(mxGetCell(p_, i))); } else v.push_back(*this); return v; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { cv::Mat img = MxArray(prhs[0]).toMat(CV_32F); // Convert to single floating point grayscale image //cv::Mat img_t; //myTranspose(img, img_t); dc::SiftFlow siftFlow; cv::Mat siftImg; siftFlow.createSIFTImage(img, siftImg); // Output to Matlab cv::Mat siftImg_t; //myTranspose(siftImg, siftImg_t); siftImg_t = siftImg; FImage out(siftImg_t.cols, siftImg_t.rows, siftImg_t.channels()); memcpy(out.pData, siftImg_t.data, siftImg_t.cols*siftImg_t.rows*siftImg_t.channels()*sizeof(float)); out.OutputToMatlab(plhs[0]); }
/** * 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 if (nrhs>0 || nlhs>1) { mexErrMsgIdAndTxt("mexopencv:error", "Wrong number of arguments"); } // get info #if ( (CV_MAJOR_VERSION<<16) + (CV_MINOR_VERSION<<8) + CV_SUBMINOR_VERSION ) < 0x020400 std::string info = "getBuildInformation not supported by OpenCV v"CV_VERSION; #else std::string info = cv::getBuildInformation(); #endif if (nlhs > 0) { plhs[0] = MxArray(info); } else { mexPrintf("%s\n", info.c_str()); } }
MVT_3D_Object::MVT_3D_Object(ENUM_OBJECT_CATEGORY object_category, const char* filepath_3dobject_model) { m_object_category = object_category; MATFile* mat = matOpen(filepath_3dobject_model,"r"); if( mat != NULL ) { mxArray* pmxCad = matGetVariable(mat, "cad"); pmxCad = mxGetCell(pmxCad,0); /* * Names of parts */ mxArray* pmxNames = mxGetField(pmxCad, 0, "pnames"); m_num_of_partsNroots = mxGetNumberOfElements(pmxNames); for( unsigned int i=0; i<m_num_of_partsNroots; i++) { mxArray* pmxName = mxGetCell(pmxNames, i); m_names_partsNroots.push_back(MxArray(pmxName).toString()); } /* * Parts2d_Front */ mxArray* pmxPars2d_front = mxGetField(pmxCad, 0, "parts2d_front"); for( unsigned int i=0; i<m_num_of_partsNroots; i++) { MVT_2D_Part_Front front; front.width = MxArray(mxGetField(pmxPars2d_front, i, "width" )).toDouble(); front.height = MxArray(mxGetField(pmxPars2d_front, i, "height" )).toDouble(); front.distance = MxArray(mxGetField(pmxPars2d_front, i, "distance")).toDouble(); cv::Mat mat_tmp = MxArray(mxGetField(pmxPars2d_front, i, "vertices")).toMat(); unsigned int n_row = mat_tmp.rows; for( unsigned int r=0; r<n_row ; r++) { front.vertices.push_back(cv::Point2d(mat_tmp.at<double>(r,0), mat_tmp.at<double>(r,1))); } front.center = MxArray(mxGetField(pmxPars2d_front, i, "center")).toPoint_<double>(); front.viewport = MxArray(mxGetField(pmxPars2d_front, i, "viewport")).toDouble(); front.name = MxArray(mxGetField(pmxPars2d_front, i, "pname")).toString(); m_2dparts_front.push_back(front); } /* * Part */ mxArray* pmxParts = mxGetField(pmxCad, 0, "parts"); m_num_of_parts = mxGetNumberOfElements(pmxParts); for( unsigned int i=0 ; i<m_num_of_parts; i++ ) { MVT_3D_Part part; /* Vertices */ mxArray* mxVertices = mxGetField(pmxParts, i, "vertices"); cv::Mat matVertices = MxArray(mxVertices).toMat(); unsigned int n_rows = matVertices.rows; for( unsigned int r=0; r<n_rows; r++) { cv::Mat matTmp = matVertices.row(r); part.vertices.push_back ( cv::Point3d( matTmp.at<double>(0), matTmp.at<double>(1), matTmp.at<double>(2) ) ); } /* plane */ MxArray MxPlane(mxGetField(pmxParts, i, "plane")); for( int j=0 ; j<4; j++ ) { part.plane[j] = MxPlane.at<double>(j); } /* center */ MxArray MxCenter(mxGetField(pmxParts, i, "center")); part.center.x = MxCenter.at<double>(0); part.center.y = MxCenter.at<double>(1); part.center.z = MxCenter.at<double>(2); /* xaxis */ MxArray MxXAxis(mxGetField(pmxParts, i, "xaxis")); part.xaxis.x = MxXAxis.at<double>(0); part.xaxis.y = MxXAxis.at<double>(1); part.xaxis.z = MxXAxis.at<double>(2); /* yaxis */ MxArray MxYAxis(mxGetField(pmxParts, i, "yaxis")); part.yaxis.x = MxYAxis.at<double>(0); part.yaxis.y = MxYAxis.at<double>(1); part.yaxis.z = MxYAxis.at<double>(2); m_3dparts.push_back(part); /* * Occlusion Information */ mxArray* pmxAzimuth = mxGetField(pmxCad, 0, "azimuth" ); m_disc_azimuth = MxArray(pmxAzimuth).toVector<MVT_AZIMUTH>(); mxArray* pmxElevation = mxGetField(pmxCad, 0, "elevation" ); m_disc_elevation = MxArray(pmxElevation).toVector<MVT_ELEVATION>(); mxArray* pmxDistance = mxGetField(pmxCad, 0, "distance" ); m_disc_distance = MxArray(pmxDistance).toVector<MVT_DISTANCE>(); mxArray* pmxParts2d = mxGetField(pmxCad, 0, "parts2d"); m_num_of_disc_azimuth = m_disc_azimuth.size(); m_num_of_disc_elevation = m_disc_elevation.size(); m_num_of_disc_distance = m_disc_distance.size(); m_is_occluded = new bool***[m_num_of_disc_azimuth]; for( unsigned int a=0; a<m_num_of_disc_azimuth; a++ ) { m_is_occluded[a] = new bool**[m_num_of_disc_elevation]; for( unsigned int e=0; e<m_num_of_disc_elevation; e++ ) { m_is_occluded[a][e] = new bool*[m_num_of_disc_distance]; for( unsigned int d=0; d<m_num_of_disc_distance; d++ ) { m_is_occluded[a][e][d] = new bool[m_num_of_partsNroots]; unsigned int idx = m_num_of_disc_distance*m_num_of_disc_elevation*a + m_num_of_disc_distance*e + d; for( unsigned int p=0; p<m_num_of_partsNroots; p++) { mxArray* pmxPart = mxGetField(pmxParts2d, idx, m_names_partsNroots[p].c_str()); m_is_occluded[a][e][d][p] = mxIsEmpty(pmxPart); } } } } } mxDestroyArray(pmxCad); matClose(mat); } }