I have a function that breaks the image into blocks for further processing using C ++ and OpenCv.
This is my code:
void imageSplit(Mat image)
{
int blockNumber = 8;
int height = image.rows;
int width = image.cols;
cv::Size smallSize(height / blockNumber, width / blockNumber);
std::vector < Mat > smallImages;
for (int y = 0; y < image.rows; y += smallSize.height)
{
for (int x = 0; x < image.cols; x += smallSize.width)
{
cv::Rect rect = cv::Rect(x, y, smallSize.width, smallSize.height);
smallImages.push_back(cv::Mat(image, rect));
}
}
}
It works great with a large region (512 x 512 works). But when I come to sizes equal to 100 x 100 px, it gives me:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.widt
h <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in
cv::Mat::Mat, file src\matrix.cpp, line 323
default exception.
Is the problem related to size? And if so, is there a way around this?
source
share