cv::Mat img; bool is_empty = img.empty(); if (is_empty) { std::cout << "Image is empty" << std::endl; }
cv::Mat img(3, 3, CV_8UC1); bool is_empty = img.empty(); if (!is_empty) { std::cout << "Image is not empty" << std::endl; }In this example, a 3x3 grayscale `cv::Mat` object is declared with an 8-bit unsigned integer data type. Its `empty()` function is called to determine if it contains any data or not. Since the matrix is initialized with a size and datatype, it will not be empty. Package Library: OpenCV