OpenCV分割图像成矩形
OpenCV Split Image into Rectangles
我有一个图像,我希望它被分割成甚至矩形到目前为止,我有这个代码,但我一直崩溃,我不知道为什么。
int cells = 10;
int rows_to_process = image.rows / cells;
int cols_to_process = image.cols;
cv::Mat img;
std::vector<cv::Mat> imageSections(cells);
int x = 0;
int y = 0;
cout << imageSections.size() << endl;
for(int i=0; i<image.rows/rows_to_process; i++)
{
cout << "i is: " << i << " x is: " << x << endl;
imageSections[i] = image(cv::Rect(x, y, cols_to_process, rows_to_process));
x += rows_to_process;
}
我已经测试了只输出x
,并且我从0到图像的大小以相等的增量获得维度。我希望将x增加到我想要开始的下一个点,但我总是崩溃。有人知道为什么吗?
我的错误在终端显示为
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat,
这个怎么样(没有测试):
int cell_Height = image.rows / 10;
int cell_width = image.cols;
std::vector<cv::Mat> imageSections(rows_to_process);
int x = 0;
int y = 0;
for(y=0; y+cell_Height<image.rows; y+=cell_Height)
{
cout << y << endl;
imageSections[i] = image(cv::Rect(x, y, cell_Width, cell_Height));
}
相关文章:
- 如何在使用OpenCV C++应用K均值后提取分割图像
- 图像分割 - 删除C 中不需要的像素
- C++/openCV - 为什么显示图像会产生 Linux 分割错误?(打开CV错误?
- FloatType图像ITK上的分割故障
- 试图均衡图像时的分割错误
- 不能通过基于指针的访问像素强度来分割 RGB 图像
- STL容器用于简单的图像分割
- 通过BGL使用Min Cut的图像分割示例
- 在opencv c++中查找图像卷积时出现分割错误(核心转储)
- 我在分割图像文件时遇到分割错误
- 基于光流的图像分割
- OpenCV:如何使用阈值正确分割图像/使用二进制图像对原始图像进行分割
- 使用OpenCV进行红外图像分割
- 3D图像的分割
- 分割文档图像
- OpenCV背景分割/从单个图像中减去
- OpenCV分割图像成矩形
- 基于图形的图像分割
- 使用OpenCV和c++将图像帧分割成8*8进行DCT
- OpenCV:无法使用 k 均值对图像进行分割