Reputation: 3
I need to acquire and save large amount of images using a camera for several hours. I'm using BitFlow SDK to handle the camera acquisition and OpenCV mainly for display and image processing. I need to find a way to save all this data in a compact, easily accessible form (creating multipage tiff files was the first objective, but there's barely any support on that).
Anyways, I'm now trying to save multiple images in one YAML file using OpenCV's FileStorage class without so much success. I can successfully write and then read one image from the YAML file I created, but as soon as I try to put more than one Mat object in the file using the << operator, I get the following error:
First-chance exception at 0x74E2C42D in BFBi_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0045F6B4. First-chance exception at 0x74E2C42D in BFBi_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0045F6B4. Unhandled exception at at 0x74E2C42D in BFBi_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0045F6B4.
Part of my code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include "resource.h"
#include "SequenceInterface.h"
#include "opencv2/core/core.hpp"
#include "persistence.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
// Control variables
BFU32 numBuffers = 10; // Allocate 10 buffers
BFU32 setupOptions = 0; // Use default setup options.
FileStorage firstImg("FirstImage.yml", FileStorage::WRITE);
FileStorage secondImg("SecondImage.yml", FileStorage::WRITE);
cout << "Creating instance of sequence interface." << endl;
SequenceInterface board(0, numBuffers, 0);
PBFU32* pBufferArray= board.getBufferArrayPointers();
Mat test(Size(1024, 1024),CV_8UC1, (void *)pBufferArray[0], (size_t)1024);
Mat test2(Size(1024, 1024),CV_8UC1, (void *)pBufferArray[1], (size_t)1024);
// -- Acquisition done here ---
...
...
// -- End of acquisition --
firstImg<<"firsttest"<< test;
firstImg<< "secondtest" << test2; // Runtime error on this line;
firstImg.release();
}
If I write test2 to secondImg, no problem occurs. I also tried to add random string objects to firstImg and there's also no problem there. Switching to XML also didn't change anything. Is there a maximum size for YAML files meaning that my images are too big for that usage?
Upvotes: 0
Views: 1093
Reputation: 41775
You can write multiple Mat
s to the same FileStorage
, just like you did. Probably you have a problem in some other parts of your code.
This, for example, works as expected:
#include <opencv2\opencv.hpp>
#include <vector>
using namespace std;
using namespace cv;
int main()
{
vector<uchar> v1(1024 * 1024, 7);
vector<uchar> v2(1024 * 1024, 9);
Mat m1(1024, 1024, CV_8UC1, v1.data(), 1024);
Mat m2(1024, 1024, CV_8UC1, v2.data(), 1024);
FileStorage fs("test.yml", FileStorage::WRITE);
fs << "m1" << m1;
fs << "m2" << m2;
return 0;
}
However, you need to
save large amount of images using a camera for several hours. I need to find a way to save all this data in a compact, easily accessible form.
So you probably don't want to save all your data in a text format in the same file, but:
imwrite
.Upvotes: 1