1 | initial version |
you could use std::ofstream
for saving variables into text file ( needs #include <fstream>
)
take a look at the test code below
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <fstream>
int main( int argc, const char** argv )
{
// Create the outputfilestream
std::ofstream output("output_test.txt");
cv::String s = "OpenCV is a great library for creating Computer Vision software";
cv::Rect r(10,30,20,20);
int i = 123;
float f = (float) 3 / 7;
cv::Mat m( 5,5,CV_8UC3,cv::Scalar( 0,255,0));
output << s << std::endl;
output << r << std::endl;
output << i << std::endl;
output << f << std::endl;
output << m << std::endl;
output << "this is a Rect : " << r << std::endl;
return 0;
}
result : output_test.txt
OpenCV is a great library for creating Computer Vision software
[20 x 20 from (10, 30)]
123
0.428571
[0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0]
this is a Rect :[20 x 20 from (10, 30)]
2 | No.2 Revision |
you could use std::ofstream
for saving variables into text file ( needs #include <fstream>
)
take a look at the test code below
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <fstream>
int main( int argc, const char** argv )
{
// Create the outputfilestream
std::ofstream output("output_test.txt");
cv::String s = "OpenCV is a great library for creating Computer Vision software";
cv::Rect r(10,30,20,20);
int i = 123;
float f = (float) 3 / 7;
cv::Mat m( 5,5,CV_8UC3,cv::Scalar( 0,255,0));
output << s << std::endl;
output << r << std::endl;
output << i << std::endl;
output << f << std::endl;
output << m << std::endl;
output << "this is a Rect : " << r << std::endl;
output.close();
return 0;
}
result : output_test.txt
OpenCV is a great library for creating Computer Vision software
[20 x 20 from (10, 30)]
123
0.428571
[0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0]
this is a Rect :[20 x 20 from (10, 30)]
note : You can store and then restore various OpenCV data structures to/from XML or YAML formats see documentation