OpenCV: reading image from std::in?

馋奶兔 提交于 2020-01-02 09:55:16

问题


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?


回答1:


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




回答2:


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());



回答3:


No,

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



来源:https://stackoverflow.com/questions/5457837/opencv-reading-image-from-stdin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!