Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

make python binder return a list

Hello

I made a custom module in c++ in which I have a function that extract a sequence from a file. My function is declare as:

CV_EXPORTS_W void read_myJFile(const String& filename, OutputArrayOfArrays img); The compilation work like a charm, how when I try to call it from python I receive that message:

OpenCV(4.0.0-pre) /home/smile/lib_dir/opencv/opencv_400/opencv/modules/core/src/matrix_wrap.cpp:1280: error: (-215:Assertion failed) i < 0 in function 'create' I investigate a little bit it is because the binder pass a Mat container as second argument of my function. Is there any way to tell the binder that the second argument of my function is std::vector<cv::mat> ? Somehow this case is a little bit like the builtin function cv::split in the sense it does not return a cv::Mat

Otherwise what should I do (write) for make the binder understand ?

Thanks in advance for any help

click to hide/show revision 2
None

updated 2018-07-14 12:08:54 -0600

berak gravatar image

make python binder return a list

Hello

I made a custom module in c++ in which I have a function that extract a sequence from a file. My function is declare as:

CV_EXPORTS_W void read_myJFile(const String& filename, OutputArrayOfArrays img);

The compilation work like a charm, how when I try to call it from python I receive that message:

OpenCV(4.0.0-pre) /home/smile/lib_dir/opencv/opencv_400/opencv/modules/core/src/matrix_wrap.cpp:1280: error: (-215:Assertion failed) i < 0 in function 'create'

I investigate a little bit it is because the binder pass a Mat container as second argument of my function. Is there any way to tell the binder that the second argument of my function is std::vector<cv::mat> ? Somehow this case is a little bit like the builtin function cv::split in the sense it does not return a cv::Mat

Otherwise what should I do (write) for make the binder understand ?

Thanks in advance for any help

make python binder return a list

Hello

I made a custom module in c++ in which I have a function that extract a sequence of images from a file. My function is declare as:

CV_EXPORTS_W void read_myJFile(const String& filename, OutputArrayOfArrays img);

The compilation work like a charm, how when I try to call it from python I receive that message:

OpenCV(4.0.0-pre) /home/smile/lib_dir/opencv/opencv_400/opencv/modules/core/src/matrix_wrap.cpp:1280: error: (-215:Assertion failed) i < 0 in function 'create'

I investigate a little bit it is because the binder pass a Mat container as second argument of my function. Is there any way to tell the binder that the second argument of my function is std::vector<cv::mat> ? Somehow this case is a little bit like the builtin function cv::split in the sense it does not return a cv::Mat

Otherwise what should I do (write) for make the binder understand ?

Thanks in advance for any help

make python binder return a list

Hello

I made a custom module in c++ in which I have a function that extract a sequence of images from a file. My function is declare as:

CV_EXPORTS_W void read_myJFile(const String& filename, OutputArrayOfArrays img);

And instantiate as:

void read_myJFile(const cv::String &filename, cv::OutputArrayOfArrays img, const int &fmt)
{

    CV_Assert(img.isMat() || img.isMatVector() || img.isUMatVector());

    std::vector<cv::Mat> data;
    std::vector<cv::Mat> dst;

// Here goes the code that  fill data with the content of the file specified.

    if(img.isMat()) // work as long data's size is lower than CV_MAX_CN.
        cv::merge(datas,img);

   if(img.isMatVector())
    {
        std::vector<cv::Mat>& tmp = *reinterpret_cast<std::vector<cv::Mat>*>(img.getObj());

        tmp = std::move(datas);
    }

    if(img.isUMatVector())
    {
        std::vector<cv::UMat>& tmp = *reinterpret_cast<std::vector<cv::UMat>*>(img.getObj());

        vmat_vumat(datas,tmp);
    }


}

The compilation work like a charm, how when I try to call it from python I receive that message:

OpenCV(4.0.0-pre) /home/smile/lib_dir/opencv/opencv_400/opencv/modules/core/src/matrix_wrap.cpp:1280: error: (-215:Assertion failed) i < 0 in function 'create'

I investigate a little bit it is because the binder pass a Mat container as second argument of my function. Is there any way to tell the binder that the second argument of my function is std::vector<cv::mat> ? Somehow this case is a little bit like the builtin function cv::split in the sense it does not return a cv::Mat

Otherwise what should I do (write) for make the binder understand ?

Thanks in advance for any help

make python binder return a list

Hello

I made a custom module in c++ in which I have a function that extract a sequence of images (aka a video with a uncommon format, not an image set) from a file. My function is declare as:

CV_EXPORTS_W void read_myJFile(const String& filename, OutputArrayOfArrays img);

And instantiate as:

void read_myJFile(const cv::String &filename, cv::OutputArrayOfArrays img, const int &fmt)
{

    CV_Assert(img.isMat() || img.isMatVector() || img.isUMatVector());

    std::vector<cv::Mat> data;
    std::vector<cv::Mat> dst;

// Here goes the code that  fill data with the content of the file specified.

    if(img.isMat()) // work as long data's size is lower than CV_MAX_CN.
        cv::merge(datas,img);

   if(img.isMatVector())
    {
        std::vector<cv::Mat>& tmp = *reinterpret_cast<std::vector<cv::Mat>*>(img.getObj());

        tmp = std::move(datas);
    }

    if(img.isUMatVector())
    {
        std::vector<cv::UMat>& tmp = *reinterpret_cast<std::vector<cv::UMat>*>(img.getObj());

        vmat_vumat(datas,tmp);
    }


}

The compilation work like a charm, how when I try to call it from python I receive that message:

OpenCV(4.0.0-pre) /home/smile/lib_dir/opencv/opencv_400/opencv/modules/core/src/matrix_wrap.cpp:1280: error: (-215:Assertion failed) i < 0 in function 'create'

I investigate a little bit it is because the binder pass a Mat container as second argument of my function. Is there any way to tell the binder that the second argument of my function is std::vector<cv::mat> ? Somehow this case is a little bit like the builtin function cv::split in the sense it does not return a cv::Mat

Otherwise what should I do (write) for make the binder understand ?

Thanks in advance for any help

make python binder return a list

Hello

I made a custom module in c++ in which I have a function that extract a sequence of images (aka a video with a uncommon format, not an image set) from a file. My function is declare as:

CV_EXPORTS_W void read_myJFile(const String& filename, OutputArrayOfArrays img);

And instantiate as:

void read_myJFile(const cv::String &filename, cv::OutputArrayOfArrays img, const int &fmt)
{

    CV_Assert(img.isMat() || img.isMatVector() || img.isUMatVector());

    std::vector<cv::Mat> data;
    std::vector<cv::Mat> dst;

// Here goes the code that  fill data with the content of the file specified.

    if(img.isMat()) // work as long data's size is lower than CV_MAX_CN.
        cv::merge(datas,img);

   if(img.isMatVector())
    {
        std::vector<cv::Mat>& tmp = *reinterpret_cast<std::vector<cv::Mat>*>(img.getObj());

        tmp = std::move(datas);
    }

    if(img.isUMatVector())
    {
        std::vector<cv::UMat>& tmp = *reinterpret_cast<std::vector<cv::UMat>*>(img.getObj());

        vmat_vumat(datas,tmp);
    }
 img.assign(data);


}

The compilation work like a charm, how when I try to call it from python I receive that message:

OpenCV(4.0.0-pre) /home/smile/lib_dir/opencv/opencv_400/opencv/modules/core/src/matrix_wrap.cpp:1280: error: (-215:Assertion failed) i < 0 in function 'create'

I investigate a little bit it is because the binder pass a Mat container as second argument of my function. Is there any way to tell the binder that the second argument of my function is std::vector<cv::mat> ? Somehow this case is a little bit like the builtin function cv::split in the sense it does not return a cv::Mat

Otherwise what should I do (write) for make the binder understand ?

Thanks in advance for any help

make python binder return a list

Hello

I made a custom module in c++ in which I have a function that extract a sequence of images (aka a video with a uncommon format, not an image set) from a file. My function is declare as:

CV_EXPORTS_W void read_myJFile(const String& filename, OutputArrayOfArrays img);

And instantiate as:

void read_myJFile(const cv::String &filename, cv::OutputArrayOfArrays img, const int &fmt)
{

    CV_Assert(img.isMat() || img.isMatVector() || img.isUMatVector());

    std::vector<cv::Mat> data;
    std::vector<cv::Mat> dst;

// Here goes the code that  fill data with the content of the file specified.

    if(img.isMat()) // work as long data's size is lower than CV_MAX_CN.
        cv::merge(datas,img);

    img.create(data.size(),1,data.front().type());
    img.assign(data);


}

The compilation work like a charm, how when I try to call it from python I receive that message:

OpenCV(4.0.0-pre) /home/smile/lib_dir/opencv/opencv_400/opencv/modules/core/src/matrix_wrap.cpp:1280: error: (-215:Assertion failed) i < 0 in function 'create'

I investigate a little bit it is because the binder pass a Mat container as second argument of my function. Is there any way to tell the binder that the second argument of my function is std::vector<cv::mat> ? Somehow this case is a little bit like the builtin function cv::split in the sense it does not return a cv::Mat

Otherwise what should I do (write) for make the binder understand ?

Thanks in advance for any help