I'm trying to create a cv::Mat from a CSV string that I pipe from a python-script. I'm currently using python 2.7, C++ and OpenCV 3.0, and all I can find is how to do it in OpenCV 2.4, but the problem is that it differs a lot from 3.0 where the ml::TrainData somehow is used instead. I don't understand how it works, and theres no example code! :-(
What my python-script does is that it pipes the np.array as CSV, it looks like this:
import sys
import numpy as np
import csv
csvToSend = csv.writer(sys.stdout, delimiter=',')
data = np.array([ [3, 7, 9],
[1, 7, 0],
[4, 12, 8]])
csvToSend.writerows(data)
The python-script is currently simulating a camera sending picture in bgr RAW format.
The piped data is received by my C++ code, this is how the code looks for the moment:
#include <iostream>
#include <string>
#include <opencv2/core/core.hpp>
using namespace std;
using namespace cv;
string values = "", csvPart;
Mat img;
int i;
int main()
{
for (i = 0; i < 3; i++)
{
cin >> csvPart; //here I get my CSV lines from python-script
if (values == "") values = values + csvPart;
else values = values + "\n" + csvPart; //makes the CVS lines look like a 3x3 matrix again
}
cout << values << endl; //prints the CVS to see that it looks like it did before piping it over to the C++ code
/* how the printed string looks like
3,7,9
1,7,0
4,12,8 */
/* Here I want to load the "values" into the Mat img
so I can do my mojo with openCV in C++ */
}
It would be much appreciated if someone could help me out with this and give me a simple code example. If there is a better way of piping the np.array over to the C++ code and load it into a cv::Mat my arms are open for you! ;-)