-1

我有一组图像如下:

int width = 5, height = 4, n = 3; // example --> 3 images of size 5x4
int sz[] = {width, height, n};
cv::Mat array(3, sz, CV_8UC1, cv::Scalar::all(0));

现在我想显示图像。我试过这样的事情:

char winName[20];
for (int i = 0; i < n; i++)
{
    sprintf(winName, "image %d", i);
    cv::imshow(winName, array.data[i]);
}

我从这里得到的:http: //answers.opencv.org/question/28184/show-many-images-in-different-windows-in-a-loop-using-one-imshow-command/

我考虑过使用for each, in表达式,但无法运行。我不太确定如何管理数组的 3 维。您能否提供一些有关如何解决该问题的信息?提前谢谢了。

4

1 回答 1

1

尝试这样的事情:

// create a vector of Mats
std::vector<cv::Mat> images(3);

// initialize each image somehow, for example with black images
for(size_t i = 0; i < images.size(); ++i)
  images[i] = cv::Mat::zeros(4, 5, CV_8U);

// show each image
for(size_t i = 0; i < images.size(); ++i) {
  char winName[20];
  sprintf(winName, "image %d", i);
  cv::imshow(winName, images[i]);
}

// wait until a key is pressed before exiting 
cv::waitKey();
于 2015-04-21T12:25:56.213 回答