Ask Your Question

Revision history [back]

May be you can try something like that :

bool MatVector(InputArray v)
{
    if (!v.isVector())
        return false;
    int i= v.type();
    if (v.type() == CV_32S)
    {
        Mat x= v.getMat();
        cout<<"Mat = "<<x<<endl;
        vector<int> myVector;
        myVector.assign(x.begin<int>(), x.end<int>());
        myVector[4]=245;
        for (int i=0;i<myVector.size();i++)
            cout<<myVector[i]<<"\t";
        cout << "Mat = " << x << endl;
        cout<<endl;
        return true;
    }
    return false;
}

int main(int argc, char **argv)
{

    Mat a = (Mat_<int>(4, 2) << 0, 1, 10, 11, 20, 21, 30, 31);
    vector<int> va = { 0, 1, 10, 11, 20, 21, 30, 31 };
    vector<double> vb = { 0, 1, 10, 11, 20, 21, 30, 31 };
    if (MatVector(a))
        cout << "vector \n";
    else
        cout << "It is not a vector \n";
    if (MatVector(va))
    {
        cout << "vector \n";
        for (int i = 0; i<va.size(); i++)
            cout << va[i] << "\t";

    }
    if (MatVector(vb))
    {
        cout << "vector \n";
        for (int i = 0; i<vb.size(); i++)
            cout << vb[i] << "\t";
   }
    else
        cout << "It is not a vector of int \n";

May be you can try something like that :

bool MatVector(InputArray v)
{
    if (!v.isVector())
        return false;
    int i= v.type();
    if (v.type() == CV_32S)
CV_32S && v.isContinuous())
    {
        Mat x= v.getMat();
        cout<<"Mat = "<<x<<endl;
        vector<int> myVector;
        myVector.assign(x.begin<int>(), x.end<int>());
        myVector[4]=245;
        for (int i=0;i<myVector.size();i++)
            cout<<myVector[i]<<"\t";
        cout << "Mat = " << x << endl;
        cout<<endl;
        return true;
    }
    return false;
}

int main(int argc, char **argv)
{

    Mat a = (Mat_<int>(4, 2) << 0, 1, 10, 11, 20, 21, 30, 31);
    vector<int> va = { 0, 1, 10, 11, 20, 21, 30, 31 };
    vector<double> vb = { 0, 1, 10, 11, 20, 21, 30, 31 };
    if (MatVector(a))
        cout << "vector \n";
    else
        cout << "It is not a vector \n";
    if (MatVector(va))
    {
        cout << "vector \n";
        for (int i = 0; i<va.size(); i++)
            cout << va[i] << "\t";

    }
    if (MatVector(vb))
    {
        cout << "vector \n";
        for (int i = 0; i<vb.size(); i++)
            cout << vb[i] << "\t";
   }
    else
        cout << "It is not a vector of int \n";