resize.cpp:4062: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
时间: 2023-10-10 07:08:57 浏览: 84
This error occurs when the input image size is empty or NULL. The assertion "ssize.empty()" checks whether the input image size is valid or not. If it is empty, the assertion fails and the program terminates with this error message.
To fix this error, ensure that the input image is not empty or NULL before passing it to the cv::resize() function. You can check the size of the input image using the cv::Size() function and validate it before calling the resize function.
Here's an example code snippet that demonstrates how to validate the input image size before resizing it:
```
cv::Mat inputImage = cv::imread("input.jpg");
if (!inputImage.empty()) {
cv::Size imageSize = inputImage.size();
if (imageSize.width > 0 && imageSize.height > 0) {
cv::Mat outputImage;
cv::resize(inputImage, outputImage, cv::Size(640, 480));
// do further processing on the resized image
}
else {
std::cerr << "Error: Input image size is invalid" << std::endl;
}
}
else {
std::cerr << "Error: Failed to read input image" << std::endl;
}
```
In this example, we first load the input image using the cv::imread() function. We then check if the input image is empty or not using the empty() function. If the input image is not empty, we check its size using the size() function. If the size is valid, we resize the image using the cv::resize() function. If the size is invalid, we print an error message.