Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #84458

OpenCv: different behavior of cv2.imread and cv2.imdecode

From maurog <qualsivoglia@dovetipare.nz>
Newsgroups comp.lang.python
Subject OpenCv: different behavior of cv2.imread and cv2.imdecode
Date 2015-01-24 10:48 +0000
Organization Aioe.org NNTP Server
Message-ID <m9vt92$uv$1@speranza.aioe.org> (permalink)

Show all headers | View raw


The starting point is an invalid jpg file, grabbed from a site showing 
pictures from a webcam while the site is updating the picture itself. So 
the upper part of the picture is ok, the lower part no.

If I execute this code
flags = cv2.CV_LOAD_IMAGE_COLOR
img = cv2.imread('bad.jpg', flags)

this message is printed on stderr

"Premature end of JPEG file"

and in the part of img np array related to the lower part of the picture 
all the values are 128 for all the RGB layers, that is black pixels.

If I execute this code, as suggested here 

https://stackoverflow.com/questions/13329445/how-to-read-image-from-in-
memory-buffer-stringio-or-from-url-with-opencv-pytho

r = open('bad.jpg','rb').read()
img_array = np.asarray(bytearray(r), dtype=np.uint8)
flags = cv2.CV_LOAD_IMAGE_COLOR
img = cv2.imdecode(img_array, flags)

no error message is shown and in the img np array there are mixed values 
in the part related to the lower part of the picture

So it looks to me that cv2.imread and cv2.imdecode handle in a different 
way the loading of a jpg image. Is it like that or am I missing something?

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

OpenCv: different behavior of cv2.imread and cv2.imdecode maurog <qualsivoglia@dovetipare.nz> - 2015-01-24 10:48 +0000

csiph-web