У меня есть функция, которая разбивает изображение на блоки для дальнейшей обработки, используя C++ и OpenCv.
Это мой код:
void imageSplit(Mat image)
{
int blockNumber = 8;
// get the image data
int height = image.rows;
int width = image.cols;
//set how many blocks and create vector to store
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);
//cout << x << " " << y << " " << smallSize.width << " " << smallSize.height << endl;
smallImages.push_back(cv::Mat(image, rect));
}
}
}
Он отлично работает с большей областью (работает 512 x 512). Но когда я перехожу к размерам, например, 100 x 100 пикселей, это дает мне:
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.
Проблема связана с размером? И если да, то есть ли обходной путь?
for (int y = 0; y < image.rows-smallSize.height; y += smallSize.height)
то же самое для х - person berak   schedule 16.04.2015