Hello there. I was trying to upsample and downsample an image with size of 256 x 256. My code is below. While it works perfect for 256 x 256 to 512 x 512, beside this code gives error below.
#include "iostream"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
int main()
{
cv::Mat image = cv::imread("C:\\Users\\Batuhan\\Desktop\\OpenCV_Workspace\\cv_Project_I\\block.png");
cv::Mat imageup2 = image.clone();
cv::Mat imageup4 = image.clone();
cv::Mat imageup5_6 = image.clone();
cv::Mat imagedown0_5 = image.clone();
cv::Mat imagedown0_25 = image.clone();
cv::Mat imagedown0_12 = image.clone();
//Upsample by 2, 4, 5.6
cv::pyrUp(image, imageup2, cv::Size(image.cols * 2, image.rows * 2 ));
cv::pyrUp(image, imageup4, cv::Size(image.cols * 4, image.rows * 4));
cv::pyrUp(image, imageup5_6, cv::Size(image.cols * 5.6, image.rows * 5.6));
//Downsample by 0.5, 0.25, 0.12
cv::pyrDown(image, imagedown0_5, cv::Size(image.cols * 0.5, image.rows * 0.5));
cv::pyrDown(image, imagedown0_25, cv::Size(image.cols * 0.25, image.rows * 0.25));
cv::pyrDown(image, imagedown0_12, cv::Size(image.cols * 0.12, image.rows * 0.12));
//Displaying Results
cv::imshow("Original Image", image);
cv::imshow("Image Upsampled by 2", imageup4);
cv::imshow("Image Upsampled by 4", imageup4);
cv::imshow("Image Upsampled by 5.6", imageup5_6);
cv::imshow("Image Downsampled by 0.5", imagedown0_5);
cv::imshow("Image Downsampled by 0.25", imagedown0_25);
cv::imshow("Image Downsampled by 0.12", imagedown0_12);
cv::waitKey();
return 0;
}
And this is the error code:
OpenCV(4.0.1) Error: Assertion failed (std::abs(dsize.width - ssize.width*2) == dsize.width % 2 && std::abs(dsize.height - ssize.height*2) == dsize.height % 2) in cv::pyrUp_, file c:\build\master_winpack-build-win64-vc15\opencv\modules\imgproc\src\pyramids.cpp, line 537 OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.0.1) Error: Assertion failed (std::abs(dsize.width - ssize.width*2) == dsize.width % 2 && std::abs(dsize.height - ssize.height*2) == dsize.height % 2) in cv::pyrUp_, file c:\build\master_winpack-build-win64-vc15\opencv\modules\imgproc\src\pyramids.cpp, line 537
What am I doing wrong? Thanks for help.