Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: reading image from std::in?

Tags:

c++

opencv

stdin

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?

like image 855
vartec Avatar asked Oct 15 '25 17:10

vartec


2 Answers

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

like image 142
ypnos Avatar answered Oct 18 '25 06:10

ypnos


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());
like image 20
t.dubrownik Avatar answered Oct 18 '25 06:10

t.dubrownik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!