It looks like the python stdin buffer is too small for images. You can run your program using the -u flag to remove buffering. See more in this answer.
Secondly, numpy.asarray is probably not the right way to get a numpy array from data, numpy.frombuffer works very well for me.
So, here is the working code (only I used cv2 instead of cv hope this is not too important):
import sys import cv2 import numpy stdin = sys.stdin.read() array = numpy.frombuffer(stdin, dtype='uint8') img = cv2.imdecode(array, 1) cv2.imshow("window", img) cv2.waitKey()
It can be performed as follows:
python -u test.py < cat.jpeg
source share