将一张图像均等分成九份,然后将这九个小块按一定间隔(九宫格效果)拷贝到新画布上。效果如下图所示:
源码:
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat src = imread("test.jpg");
if (src.empty())
{
cout << "No Image!" << endl;
system("pause");
return -1;
}
//原图宽高
int width = src.cols;
int height = src.rows;
int num = 3;//小方块数量(可实现任意等份分割)
//制作九宫格每个小方块宽高
int step_x = width / num;
int step_y = height / num;
//重新resize图片尺寸
resize(src, src, Size(step_x * num, step_y * num), 1, 1, INTER_LINEAR);
int space = 5; //空白间隔(实现九宫格效果)
Mat canvas = Mat(Size(src.cols + space * (num-1), src.rows + space * (num - 1)), CV_8UC3, Scalar(255,255,255)); //画布,用来制作九宫格图片
/