I'm trying to load the image from pipe such as stdin, named pipe, etc.
This is my sample code:
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char **argv) {
Mat img; if(argc > 1) img = imread(argv[1]); else img = imread("/dev/stdin"); printf("rows = %d, cols = %d\\n", img.rows, img.cols); imshow("original", img); while (waitKey(1) != 'q'); return 0;
}
./a.out image.jpg
will work, but
./a.out < image.jpg
and
mkfifo img.pipe
./a.out img.pipe
cat image.jpg > img.pipe
won't work and rows and cols of Mat img are 0.
What's the difference between real file and pipe?
The function imread
is to read image from block device, instead of stream device. the local file is of block, and pipe is of stream, that's why the function imread
can not read image from pipes, sockets, etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.