Skip to content

error: (-211:One of the arguments' values is out of range) m_validSize >= m_size this problem can be resolved my decreasig k parameter in function 'Push' #3227

@DelinQu

Description

@DelinQu
System information (version)
  • OpenCV => 4.5.5
  • Operating System / Platform => Ubuntu 20.04
  • Compiler => VScode, g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Detailed description

I am trying to calculate optical flow by interpolating KLT flow using RICInterpolator but got an unexcepted error:

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.5.5-dev) /home/qdl/Downloads/opencv_contrib/modules/ximgproc/src/sparse_match_interpolators.cpp:1034: error: (-211:One of the arguments' values is out of range)  m_validSize >= m_size this problem can be resolved my decreasig k parameter in function 'Push'
Steps to reproduce
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

void test(const Mat &preFrame, const Mat &curFrame, Mat &retFrame){
    // convert to gray
    Mat pre_gray_frame, cur_gray_frame;
    Mat flow(preFrame.rows, preFrame.cols, CV_8UC2);

    cvtColor(preFrame, pre_gray_frame, COLOR_BGR2GRAY);
    cvtColor(curFrame, cur_gray_frame, COLOR_BGR2GRAY);

    // detect features
    vector<Point2f> prePts, curPts;
    goodFeaturesToTrack(pre_gray_frame, prePts, 10000, 0.03, 0.01, Mat());

    // calculate optical flow
    vector<uchar> status, err;
    calcOpticalFlowPyrLK(pre_gray_frame, cur_gray_frame, prePts, curPts, status, err);

    vector<string> image_names = {"pre_gray_frame", "cur_gray_frame", "preFrame", "curFrame", "flow"};
    vector<Mat> images = {pre_gray_frame, cur_gray_frame, preFrame, curFrame, flow};
    for (int i = 0; i < images.size(); i++)
    {
        cout    << image_names[i] 
                << " channels " << images[i].channels() << endl 
                << " size " << images[i].size() << endl; 
    }

    // interpolate
    interp.get()->interpolate(preFrame, prePts, curFrame, curPts, flow);
    // interp.get()->interpolate(pre_gray_frame, prePts, cur_gray_frame, curPts, flow); // got another error when 8-bit single-channel. 
    cout << " flow shape :  " << flow.size() << endl;
}

int main(int argc, char** argv)
{
    Mat im1 = imread('./test1.png', 1), im2 = imread('test2.png', 1), im_ret;
    test(im1, im2, im_ret);
    return 0;
}
  • I got another error when using 8-bit single-channel gray images in interpolate function following the Doc. I am not sure about whether there is an error in the Doc or my code and feel so confused. Could anyone help me? Any suggestion will be appreciated!
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.5.5-dev) /home/qdl/Downloads/opencv/modules/imgproc/src/color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<3>; VDepth = cv::impl::{anonymous}::Set<0, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = cv::impl::<unnamed>::NONE; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Invalid number of channels in input image:
>     'VScn::contains(scn)'
> where
>     'scn' is 1
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there.
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions