pyrDown出错

时间:2017-04-22 16:43:53

标签: c++ opencv computer-vision opencv3.0

我是Open36V的新手,我正在实施模板匹配的分层搜索,在一个步骤中,我需要对图像进行下采样。但是,我得到了注意到的错误。

另一点是当我注释掉第一个pyrDown时,它适用于第二个,第一个pyrDown正在生成错误,但我不知道为什么。有人,请帮助我理解为什么会这样。

        Mat sampled_image,sampled_reference;

        GaussianBlur( prev_image , filtered_image , Size( 5, 5 ), 0 ,0 );
        GaussianBlur(prev_reference, filtered_reference, Size(5,5), 0, 0);


         pyrDown( filtered_image, sampled_image, Size(filtered_image.rows/2 , filtered_image.cols/2));

         pyrDown( filtered_reference, sampled_reference, Size(filtered_reference.rows/2 , filtered_reference.cols/2));


        image_array.push(sampled_image); // level 1 image   LEVEL 1 IMAGE
        reference_array.push(sampled_reference); // level 1 reference

        prev_image = sampled_image;
        prev_reference= sampled_reference;

抛出错误:

Width = 480 Height= 300 (of the filtered_image )
OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0 && std::abs(dsize.width*2 - ssize.width) <= 2 && std::abs(dsize.height*2 - ssize.height) <= 2) in pyrDown_, file C:\opencv-3.2.0\source\modules\imgproc\src\pyramids.cpp, line 873
terminate called after throwing an instance of 'cv::Exception' what():  C:\opencv-3.2.0\source\modules\imgproc\src\pyramids.cpp:873: error: (-215) ssize.width > 0 && ssize.height > 0 && std::abs(dsize.width*2 - ssize.width) <= 2 && std::abs(dsize.height*2 - ssize.height) <= 2 in function pyrDown_

1 个答案:

答案 0 :(得分:1)

如果不知道两张图片的尺寸,我无法确定,但我觉得你的参考图像是方形的。

OpenCV pyrdown文档(它适用于opencv 2.4,但是你可以从3.0重定向到那里它应该有效。这是重要的部分:

|dstsize.width  * 2 - src.cols| <= 2
|dstsize.height * 2 - src.rows| <= 2

这是失败的断言。我认为你已经交换了坐标,这可能会被方形图像(rows == cols)忽略,但是否则会失败。

尺寸应为(宽度,高度)形式。宽度是列数,高度是行数。尝试做:

cv::pyrDown( input, output, Size( input.cols/2, input.rows/2 );