简体   繁体   中英

vector of cv::Mat

My class contains a vector of cv::Mat images.

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.

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". 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM