I started to use cv::format() a while ago to format my data in a CSV like text stream, and noticed it worked oddely : no problem of importance when used on a N * P cv::Mat where P is greater or equal to 2. The only matter then would be the useless spaces before each row but the first, but we can trim them afterwards easily.
But when P is equal to 1 (the matrix is a column), cv::format() does not seem to add the end of line signals between lines and I end up with a single line full of characters with no separation in between.
Here is an exemple, where I fill up two matrices and display them before and after using cv::format() :
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace std;
int main()
{
int dimensions = 5;
int sampleCount = 4;
cv::Mat points(sampleCount,dimensions, CV_32F,cv::Scalar(10));
cout<<points<<endl;
cout<<cv::format(points,"csv")<<endl;
cv::Mat points2(sampleCount,1, CV_32F,cv::Scalar(10));
cout<<points2<<endl;
cout<<cv::format(points2,"csv")<<endl;
return 0;
}
The output given is :
[10, 10, 10, 10, 10;
10, 10, 10, 10, 10;
10, 10, 10, 10, 10;
10, 10, 10, 10, 10]
10, 10, 10, 10, 10
10, 10, 10, 10, 10
10, 10, 10, 10, 10
10, 10, 10, 10, 10
[10; 10; 10; 10]
10101010
The extra spaces in the first case seem to come from the << operator which gives a nicer display since it displays a bracket on first line.
As for the second and most important case, I don't know where it comes from but I think this should be fixed.
Note the "csv" format seems not to be the only one with this kind of output, I tried with "python" and got a similar [10101010] output.