3

Is there some way of using OpenCV's imread function to read from std::in?

Mat imread( const string& filename, int flags=1 );

Function accepts only filename, but is there some "magic" value for stdin?

vartec
  • 131,205
  • 36
  • 218
  • 244

3 Answers3

3

OpenCV provides imdecode functions that work on buffers instead of filename. You would need to read stdin into a buffer first.

http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html

ypnos
  • 50,202
  • 14
  • 95
  • 141
1

If you want a very quick hack, here's something that seems to work on Linux:

#include <unistd.h>

/* snip */ 

std::stringstream ss;
ss << "/proc/" << getpid() << "/fd/0";

cv::Mat m = cv::imread(ss.str());
t.dubrownik
  • 12,464
  • 1
  • 17
  • 6
0

No,

But if really you want to, you can stream stdin into a named pipe (mkfifo) and read from it.

BenjaminB
  • 1,809
  • 3
  • 18
  • 32