// 获取图像尺寸
int width = src.cols;
int height = src.rows;
// 计算裁剪区域的大小
int cropWidth = static_cast<int>(width * cropRatio);
int cropHeight = static_cast<int>(height * cropRatio);
// 计算裁剪区域的起始坐标(居中裁剪)
int startX = (width - cropWidth) / 2;
int startY = (height - cropHeight) / 2;
pixelsCroppedX = startX;
pixelsCroppedY = startY;
// 创建裁剪区域的矩形
Rect cropRect(startX, startY, cropWidth, cropHeight);
// 裁剪图像并返回
return src(cropRect).clone();
}
// 创建中心区域蒙版(用于屏蔽图像中心区域)
Mat createCenterMask(int width, int height, int blockSize) {
// 创建全白蒙版(255表示不屏蔽)
Mat mask = Mat(height, width, CV_8UC1, Scalar(255));
// 计算中心区域
int centerX = width / 2;
int centerY = height / 2;
int halfBlock = blockSize / 2;
// 确定中心区域的边界(确保不超出图像范围)
int x1 = max(0, centerX - halfBlock);
int y1 = max(0, centerY - halfBlock);
int x2 = min(width - 1, centerX + halfBlock);
int y2 = min(height - 1, centerY + halfBlock);
// 第一张图像处理(作为基准)
if (mapCollage.empty()) {
// 计算图像居中放置的位置
int x = (mapSize - img.cols) / 2;
int y = (mapSize - img.rows) / 2;
int width = img.cols;
int height = img.rows;