I am trying to pass couple of cv::Mat object from one program to another, both implemented in C++ and preferably run in parallel. The cv::Mat does not have an image in it, so imread and imwrite are not useful here (we can not compress data with traditional image compressing methods). One solution would be writing the matrix in a file (CSV file for example), but since the program process too much information, the disk will be the bottleneck, besides, I soon will run out of disk space.
After some digging, I found pipes (name or unnamed) as a useful solution. I wrote two pilot programs: Producer.cpp:
int main(int argc, char* argv[])
{
Mat image;
image = imread(argv[1]);
cout << image;
cout.flush();
return 0;
}
Consumer.cpp:
int main(int argc, char* argv[])
{
Mat image;
cin >> image;
imshow("Image", image);
waitKey();
return 0;
}
Surprisingly, the second program will not compile.
mismatched types ‘_CharT2*’ and ‘cv::Mat’ cin >> image;
Which means (I guess) ">>" operator is not overloaded for cv::Mat. Even though we might be able to override the >> operator, since the matrix is big, and stdin and stdout are text based, it would not be the best neither the easiest way.
So, back to main question: What is the best way of passing a cv::Mat object (or potentially any other binary object) from one program to another?