How to write a vector<cv::Mat> to a single file? [closed]
Hello, I found a pull request https://github.com/opencv/opencv/pull.... Which states that "imwrite for multipage images implemented"
But I am unable to find the function that does so.
I used cv::imreadmulti() to read a stacked tiff file (one file with multiple images). Then did some processing on them. Now, I have a vector<cv::mat> where each Mat is a Tiff image.
How do I write them to one file which would be similar to the file I read using imreadmulti()?
Thank you
apparently, you can imwrite() a vector<mat>
Hi, I tried imwrite but could not get it to work. Could you please give me an example
This is what I tried:
std::vector<cv::mat> xy_stack; cv::imreadmulti(input_file, xy_stack);
cv::imwrite("file.tiff", xy_stack);
It does not work
Error:
OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in cv::_InputArray::getMat_, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\matrix.cpp, line 1253
i tested like below and see no problem with your code
My images are: cv::Mat polar(iPolarRows, iPolarColumns, CV_8UC1)
Does the type have anything to do with the problem? I tried 16U/16S/8S/8U all give me same error OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in cv::_InputArray::getMat_, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\matrix.cpp, line 1253
Hi Strukmen
I tried running your code using a tif file i had
int main(int argc, char *argv[]) {
}
And I get the same error at the first imwrite
OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in cv::_InputArray::getMat_, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\matrix.cpp, line 1253
Emailed 50.tif, kindly check
works flawlessly
what about when you try to show images
What could be the issue then?
imshow works. I ran the code you gave I see 3 images and then the imwrite fails with message
OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in cv::_InputArray::getMat_
run "opencv_version -v" in cmd and paste here the output
'opencv_version' is not recognized as an internal or external command, operable program or batch file.
I am on windows not sure if this would work. Is there any other way to check version