[英]vector of cv::Mat
My class contains a vector of cv::Mat images.我的课程包含一个 cv::Mat 图像向量。
class reconstructed_object
{
private:
std::vector<cv::Mat> raw_images;
public:
reconstructed_object();
show_images();
}
In its constructor 3 images from my harddrive are read using cv::imread("path") and pushed into the vector.在其构造函数中,使用 cv::imread("path") 从我的硬盘驱动器中读取 3 张图像并将其推入向量中。
reconstructed_object::reconstructed_object()
{
raw_images.push_back(cv::imread("path_1").clone());
raw_images.push_back(cv::imread("path_2").clone());
raw_images.push_back(cv::imread("path_3").clone());
}
void reconstructed_object::show_images()
{
for (int i=0; i < raw_images.size(); i++)
{
cv::imshow("raw_image", raw_images[i]);
cv::waitKey(1000);
}
}
After reading all the suggestions about deep copy I used the "clone"-method.在阅读了有关深拷贝的所有建议后,我使用了“克隆”方法。 However the vector is filled with three times the image from "path_3".
然而,向量填充了“path_3”中图像的三倍。 How can I save the different pictures in the vector?
如何将不同的图片保存在矢量中?
Try:尝试:
cv::imshow("raw_image"+ std::to_string(i), raw_images[i]);
I suggest that problem is that all your windows where you pass images have the same name.我建议问题是您传递图像的所有窗口都具有相同的名称。 So, each next member of the vector just overlaps the images before.
因此,向量的每个下一个成员只是与之前的图像重叠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.