Reputation: 20450
Here's how my code looks like:
// 10 rows and 2 cols matrix.
CvMat* results = cvCreateMat(10, 2, CV_32FC1);
// Some operations ...
ann->predict(samples, results);
// How to print out the **results** ?
Is there any C++ API for this ?
Upvotes: 1
Views: 3817
Reputation: 2517
In OpenCV 3, cv::Mat(results)
does not work anymore (at least since OpenCV 3.2, the version I used).
Instead, you should use cvarrToMat:
std::cout << cv::cvarrToMat(results) << '\n';
Upvotes: 0
Reputation: 11201
What works is std::cout << cv::Mat(results) << '\n';
This is since cv::Mat
can be constructed from CvMat
and cv::Mat
has operator <<
overloaded.
Upvotes: 2
Reputation: 21
Hi here is mine to be used for viewing inside data of CvMat.
void printMat(CvMat* mat, char* filename)
{
FILE *pf =fopen(filename,"w");
fprintf(pf,"(%dx%d)\n",mat->cols,mat->rows);
for(int i=0; i<mat->rows; i++)
{
if(i==0)
{
for(int j=0; j<mat->cols; j++) fprintf(pf,"%10d",j+1);
}
fprintf(pf,"\n%4d: ",i+1);
for(int j=0; j<mat->cols; j++)
{
fprintf(pf,"%10.2f",cvGet2D(mat,i,j).val[0]);
}
}
fflush(pf);
fclose(pf);
}
Upvotes: 2
Reputation: 96109
std::cout << results <<"\n";
As an extra bonus this prints in a format that can be copied straight into matlab
Upvotes: 1