wing
wing

Reputation: 151

OpenCV: Failed to read image from pipe

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?

Upvotes: 2

Views: 924

Answers (1)

Peixu Zhu
Peixu Zhu

Reputation: 2151

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.

Upvotes: 0

Related Questions