Exemple #1
0
std::vector<cv::Vec<T,cn> > MxArrayToVectorVec(const MxArray& arr)
{
    std::vector<cv::Vec<T,cn> > vv;
    if (arr.isNumeric()) {
        if (arr.numel() == cn)
            vv.push_back(arr.toVec<T,cn>());
        else
            arr.toMat(cv::Vec<T,cn>::depth).reshape(cn, 0).copyTo(vv);
    }
    else if (arr.isCell()) {
        /*
        std::vector<MxArray> va(arr.toVector<MxArray>());
        vv.reserve(va.size());
        for (std::vector<MxArray>::const_iterator it = va.begin(); it != va.end(); ++it)
            vv.push_back(it->toVec<T,cn>());
        */
        vv = arr.toVector(
            std::const_mem_fun_ref_t<cv::Vec<T,cn>, MxArray>(
                &MxArray::toVec<T,cn>));
    }
    else
        mexErrMsgIdAndTxt("mexopencv:error",
            "Unable to convert MxArray to std::vector<cv::Vec<T,cn>>");
    return vv;
}
Exemple #2
0
std::vector<cv::Rect_<T> > MxArrayToVectorRect(const MxArray& arr)
{
    std::vector<cv::Rect_<T> > vr;
    if (arr.isNumeric()) {
        if (arr.numel() == 4)
            vr.push_back(arr.toRect_<T>());
        else
            arr.toMat(cv::DataType<T>::depth).reshape(4, 0).copyTo(vr);
    }
    else if (arr.isCell()) {
        /*
        std::vector<MxArray> va(arr.toVector<MxArray>());
        vr.reserve(va.size());
        for (std::vector<MxArray>::const_iterator it = va.begin(); it != va.end(); ++it)
            vr.push_back(it->toRect_<T>());
        */
        vr = arr.toVector(
            std::const_mem_fun_ref_t<cv::Rect_<T>, MxArray>(
                &MxArray::toRect_<T>));
    }
    else
        mexErrMsgIdAndTxt("mexopencv:error",
            "Unable to convert MxArray to std::vector<cv::Rect_<T>>");
    return vr;
}
RansacParams toRansacParams(const MxArray &arr)
{
    return RansacParams(
        arr.at("Size").toInt(),
        arr.at("Thresh").toFloat(),
        arr.at("Eps").toFloat(),
        arr.at("Prob").toFloat());
}
Exemple #4
0
cv::TermCriteria MxArray::toTermCriteria(mwIndex index) const
{
    const MxArray _type(at("type", index));
    return cv::TermCriteria(
        (_type.isChar()) ? TermCritType[_type.toString()] : _type.toInt(),
        at("maxCount", index).toInt(),
        at("epsilon", index).toDouble()
    );
}
Exemple #5
0
/// Create a struct
mxArray* valueStruct(const Mat& R1, const Mat& R2, const Mat& P1, const Mat& P2,
    const Mat& Q, const Rect& roi1, const Rect& roi2)
{
    MxArray s = MxArray::Struct(_fieldnames,7);
    s.set("R1",R1);
    s.set("R2",R2);
    s.set("P1",P1);
    s.set("P2",P2);
    s.set("Q",Q);
    s.set("roi1",roi1);
    s.set("roi2",roi2);
    return s;
}
MxArray toStruct(const vector<DTrees::Split>& splits)
{
    const char* fields[] = {"varIdx", "inversed", "quality", "next", "c",
        "subsetOfs"};
    MxArray s = MxArray::Struct(fields, 6, 1, splits.size());
    for (size_t i=0; i<splits.size(); ++i) {
        s.set("varIdx",    splits[i].varIdx,    i);
        s.set("inversed",  splits[i].inversed,  i);
        s.set("quality",   splits[i].quality,   i);
        s.set("next",      splits[i].next,      i);
        s.set("c",         splits[i].c,         i);
        s.set("subsetOfs", splits[i].subsetOfs, i);
    }
    return s;
}
MxArray toStruct(const vector<DTrees::Node>& nodes)
{
    const char* fields[] = {"value", "classIdx", "parent", "left", "right",
        "defaultDir", "split"};
    MxArray s = MxArray::Struct(fields, 7, 1, nodes.size());
    for (size_t i=0; i<nodes.size(); ++i) {
        s.set("value",      nodes[i].value,      i);
        s.set("classIdx",   nodes[i].classIdx,   i);
        s.set("parent",     nodes[i].parent,     i);
        s.set("left",       nodes[i].left,       i);
        s.set("right",      nodes[i].right,      i);
        s.set("defaultDir", nodes[i].defaultDir, i);
        s.set("split",      nodes[i].split,      i);
    }
    return s;
}
Exemple #8
0
std::vector<cv::Matx<T,m,n> > MxArrayToVectorMatx(const MxArray& arr)
{
    std::vector<cv::Matx<T,m,n> > vx;
    if (arr.isNumeric()) {
        vx.push_back(arr.toMatx<T,m,n>());
    }
    else if (arr.isCell()) {
        /*
        std::vector<MxArray> va(arr.toVector<MxArray>());
        vx.reserve(va.size());
        for (std::vector<MxArray>::const_iterator it = va.begin(); it != va.end(); ++it)
            vx.push_back(it->toMatx<T,m,n>());
        */
        vx = arr.toVector(
            std::const_mem_fun_ref_t<cv::Matx<T,m,n>, MxArray>(
                &MxArray::toMatx<T,m,n>));
    }
    else
        mexErrMsgIdAndTxt("mexopencv:error",
            "Unable to convert MxArray to std::vector<cv::Matx<T,m,n>>");
    return vx;
}
Exemple #9
0
std::vector<std::vector<T> > MxArrayToVectorVectorPrimitive(const MxArray& arr)
{
    /*
    std::vector<MxArray> vva(arr.toVector<MxArray>());
    std::vector<std::vector<T> > vv;
    vv.reserve(vva.size());
    for (std::vector<MxArray>::const_iterator it = vva.begin(); it != vva.end(); ++it) {
        vv.push_back(it->toVector<T>());
    }
    return vv;
    */
    typedef std::vector<T> VecT;
    std::const_mem_fun_ref_t<VecT, MxArray> func(&MxArray::toVector<T>);
    return arr.toVector(func);
}
Exemple #10
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
    nargchk((nrhs==1 || nrhs==2) && nlhs<=1);

    // Argument vector
    vector<MxArray> rhs(prhs, prhs+nrhs);
    string method(rhs[0].toString());

    // Operation switch
    if (method == "checkHardwareSupport") {
        nargchk(nrhs==1 && nlhs<=1);
        const char *fields[23] = {"MMX", "SSE", "SSE2", "SSE3", "SSSE3",
            "SSE4_1", "SSE4_2", "POPCNT", "FP16", "AVX", "AVX2", "FMA3",
            "AVX_512F", "AVX_512BW", "AVX_512CD", "AVX_512DQ", "AVX_512ER",
            "AVX_512IFMA512", "AVX_512PF", "AVX_512VBMI", "AVX_512VL", "NEON",
            "VSX"};
        MxArray s = MxArray::Struct(fields, 23);
        s.set(fields[0],  checkHardwareSupport(CV_CPU_MMX));
        s.set(fields[1],  checkHardwareSupport(CV_CPU_SSE));
        s.set(fields[2],  checkHardwareSupport(CV_CPU_SSE2));
        s.set(fields[3],  checkHardwareSupport(CV_CPU_SSE3));
        s.set(fields[4],  checkHardwareSupport(CV_CPU_SSSE3));
        s.set(fields[5],  checkHardwareSupport(CV_CPU_SSE4_1));
        s.set(fields[6],  checkHardwareSupport(CV_CPU_SSE4_2));
        s.set(fields[7],  checkHardwareSupport(CV_CPU_POPCNT));
        s.set(fields[8],  checkHardwareSupport(CV_CPU_FP16));
        s.set(fields[9],  checkHardwareSupport(CV_CPU_AVX));
        s.set(fields[10], checkHardwareSupport(CV_CPU_AVX2));
        s.set(fields[11], checkHardwareSupport(CV_CPU_FMA3));
        s.set(fields[12], checkHardwareSupport(CV_CPU_AVX_512F));
        s.set(fields[13], checkHardwareSupport(CV_CPU_AVX_512BW));
        s.set(fields[14], checkHardwareSupport(CV_CPU_AVX_512CD));
        s.set(fields[15], checkHardwareSupport(CV_CPU_AVX_512DQ));
        s.set(fields[16], checkHardwareSupport(CV_CPU_AVX_512ER));
        s.set(fields[17], checkHardwareSupport(CV_CPU_AVX_512IFMA512));
        s.set(fields[18], checkHardwareSupport(CV_CPU_AVX_512PF));
        s.set(fields[19], checkHardwareSupport(CV_CPU_AVX_512VBMI));
        s.set(fields[20], checkHardwareSupport(CV_CPU_AVX_512VL));
        s.set(fields[21], checkHardwareSupport(CV_CPU_NEON));
        s.set(fields[22], checkHardwareSupport(CV_CPU_VSX));
        plhs[0] = s;
    }
    else if (method == "getBuildInformation") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(getBuildInformation());
    }
    else if (method == "version") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(string(CV_VERSION));
    }
    else if (method == "getNumberOfCPUs") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(getNumberOfCPUs());
    }
    else if (method == "getNumThreads") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(getNumThreads());
    }
    else if (method == "setNumThreads") {
        nargchk(nrhs==2 && nlhs==0);
        setNumThreads(rhs[1].toInt());
    }
    else if (method == "useOptimized") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(useOptimized());
    }
    else if (method == "setUseOptimized") {
        nargchk(nrhs==2 && nlhs==0);
        setUseOptimized(rhs[1].toBool());
    }
    else if (method == "getIppVersion") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(ipp::getIppVersion());
    }
    else if (method == "useIPP") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(ipp::useIPP());
    }
    else if (method == "setUseIPP") {
        nargchk(nrhs==2 && nlhs==0);
        ipp::setUseIPP(rhs[1].toBool());
    }
    else if (method == "useIPP_NE") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(ipp::useIPP_NE());
    }
    else if (method == "setUseIPP_NE") {
        nargchk(nrhs==2 && nlhs==0);
        ipp::setUseIPP_NE(rhs[1].toBool());
    }
    else if (method == "haveOpenVX") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(haveOpenVX());
    }
    else if (method == "useOpenVX") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(useOpenVX());
    }
    else if (method == "setUseOpenVX") {
        nargchk(nrhs==2 && nlhs==0);
        setUseOpenVX(rhs[1].toBool());
    }
    else if (method == "haveOpenCL") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(ocl::haveOpenCL());
    }
    else if (method == "haveAmdBlas") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(ocl::haveAmdBlas());
    }
    else if (method == "haveAmdFft") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(ocl::haveAmdFft());
    }
    else if (method == "haveSVM") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(ocl::haveSVM());
    }
    else if (method == "useOpenCL") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(ocl::useOpenCL());
    }
    else if (method == "setUseOpenCL") {
        nargchk(nrhs==2 && nlhs==0);
        ocl::setUseOpenCL(rhs[1].toBool());
    }
    else if (method == "getPlatfomsInfo") {
        nargchk(nrhs==1 && nlhs<=1);
        vector<ocl::PlatformInfo> vpi;
        ocl::getPlatfomsInfo(vpi);
        plhs[0] = toStruct(vpi);
    }
    else if (method == "getCudaEnabledDeviceCount") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(cuda::getCudaEnabledDeviceCount());
    }
    else if (method == "getDevice") {
        nargchk(nrhs==1 && nlhs<=1);
        plhs[0] = MxArray(cuda::getDevice());
    }
    else if (method == "setDevice") {
        nargchk(nrhs==2 && nlhs==0);
        cuda::setDevice(rhs[1].toInt());
    }
    else if (method == "resetDevice") {
        nargchk(nrhs==1 && nlhs==0);
        cuda::resetDevice();
    }
    else if (method == "deviceSupports") {
        nargchk(nrhs==1 && nlhs<=1);
        const char *fields[10] = {"Compute10", "Compute11", "Compute12",
            "Compute13", "Compute20", "Compute21", "Compute30", "Compute32",
            "Compute35", "Compute50"};
        MxArray s = MxArray::Struct(fields, 10);
        s.set(fields[0], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_10));
        s.set(fields[1], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_11));
        s.set(fields[2], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_12));
        s.set(fields[3], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_13));
        s.set(fields[4], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_20));
        s.set(fields[5], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_21));
        s.set(fields[6], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_30));
        s.set(fields[7], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_32));
        s.set(fields[8], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_35));
        s.set(fields[9], cuda::deviceSupports(cv::cuda::FEATURE_SET_COMPUTE_50));
        plhs[0] = s;
    }
    else if (method == "printCudaDeviceInfo") {
        nargchk(nrhs==2 && nlhs==0);
        cuda::printCudaDeviceInfo(rhs[1].toInt());
    }
    else if (method == "printShortCudaDeviceInfo") {
        nargchk(nrhs==2 && nlhs==0);
        cuda::printShortCudaDeviceInfo(rhs[1].toInt());
    }
    else if (method == "deviceInfo") {
        nargchk(nrhs==2 && nlhs<=1);
        cuda::DeviceInfo di(rhs[1].toInt());
        plhs[0] = toStruct(di);
    }
    else if (method == "useTegra") {
        nargchk(nrhs==1 && nlhs<=1);
#ifdef HAVE_TEGRA_OPTIMIZATION
        plhs[0] = MxArray(tegra::useTegra());
#else
        plhs[0] = MxArray(false);
#endif
    }
    else if (method == "setUseTegra") {
        nargchk(nrhs==2 && nlhs==0);
#ifdef HAVE_TEGRA_OPTIMIZATION
        tegra::setUseTegra(rhs[1].toBool());
#endif
    }
    else
        mexErrMsgIdAndTxt("mexopencv:error",
            "Unrecognized operation %s", method.c_str());
}