gpt4 book ai didi

image - OpenCV中的Concat图像

转载 作者:行者123 更新时间:2023-12-02 17:12:15 34 4
gpt4 key购买 nike

我正在尝试将许多图像串联在唯一图像内的网格中。我有一个 vector ,其中收集了400张图像(每个图像都是一个直方图)。我想做的是将所有400个直方图连接成唯一的最终直方图。

我该如何解决?

最佳答案

设置网格尺寸后,您只需找出每个图像应在网格内复制的位置。然后在正确的位置使用copyTo将产生所需的输出。

看一下代码。评论应阐明每个步骤。让我知道它对您有用。

#include <opencv2\opencv.hpp>
using namespace cv;

int main()
{
// Define the size of your images
Size sz(20,20);

// Create some random images (will be your histograms)
vector<Mat3b> images(400);
for (int i = 0; i < images.size(); ++i)
{
Vec3b color(rand() & 255, rand() & 255, rand() & 255);
images[i] = Mat3b(sz, color);
}

//////////////////
// Create Grid
//////////////////

// Define number of columns in the grid
int n_cols = 20;
// Define correct number of rows, according to columns
int n_rows = (images.size() / n_cols) + ((images.size() % n_cols) ? 1 : 0);

// Create a black image with correct size
Mat3b grid(n_rows * sz.height, n_cols * sz.width, Vec3b(0,0,0));

// For each image
for (int i = 0; i < images.size(); ++i)
{
// Get x,y position in the grid
int x = (i % n_cols) * sz.width;
int y = (i / n_cols) * sz.height;

// Select the roi in the grid
Rect roi(x,y,sz.width,sz.height);

// Copy the image into the roi
images[i].copyTo(grid(roi));
}
return 0;
}

可能的输出:

enter image description here

关于image - OpenCV中的Concat图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32886004/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com