Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error during image decoding (imdecode) using python

I use puthon 2.7, windows 7 and opencv 2.4.6. and I try to run the following code:

https://github.com/kyatou/python-opencv_tutorial/blob/master/08_image_encode_decode.py

#import opencv library
import cv2
import sys
import numpy

argvs=sys.argv
if (len(argvs) != 2):
 print 'Usage: # python %s imagefilename' % argvs[0]
 quit()

imagefilename = argvs[1]
try:
  img=cv2.imread(imagefilename, 1)
except:
  print 'faild to load %s' % imagefilename
  quit()

#encode to jpeg format
#encode param image quality 0 to 100. default:95
#if you want to shrink data size, choose low image quality.
encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90]
result,encimg=cv2.imencode('.jpg',img,encode_param)
if False==result:
  print 'could not encode image!'
  quit()

#decode from jpeg format
decimg=cv2.imdecode(encimg,1)

cv2.imshow('Source Image',img)
cv2.imshow('Decoded image',decimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

I keep getting the following error:

result, encimg = cv2.imencode('.jpg', img, [1, 90]) 
TypeError: 'bool' object is not iterable

I have tried a lot of things: reinstall opencv, convert cv2 to cv code and searched different forums but I keep getting this error. Am I missing something? Is there someone who can run this code without getting the error?

BTW: Other opencv code (taking pictures from webcam) runs without problems....

At the moment I save the image to a temp JPG file. Using the imencode function I want to create the jpg file in the memory.

Thanks in advance and with best regards.

Error during image decoding (imdecode) using python

I use puthon 2.7, windows 7 and opencv 2.4.6. and I try to run the following code:

https://github.com/kyatou/python-opencv_tutorial/blob/master/08_image_encode_decode.py

#import opencv library
import cv2
import sys
import numpy

argvs=sys.argv
if (len(argvs) != 2):
 print 'Usage: # python %s imagefilename' % argvs[0]
 quit()

imagefilename = argvs[1]
try:
  img=cv2.imread(imagefilename, 1)
except:
  print 'faild to load %s' % imagefilename
  quit()

#encode to jpeg format
#encode param image quality 0 to 100. default:95
#if you want to shrink data size, choose low image quality.
encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90]
encode_param=[1, 90]
result,encimg=cv2.imencode('.jpg',img,encode_param)
if False==result:
  print 'could not encode image!'
  quit()

#decode from jpeg format
decimg=cv2.imdecode(encimg,1)

cv2.imshow('Source Image',img)
cv2.imshow('Decoded image',decimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

I keep getting the following error:

result, encimg = cv2.imencode('.jpg', img, [1, 90]) 
TypeError: 'bool' object is not iterable

I have tried a lot of things: reinstall opencv, convert cv2 to cv code and searched different forums but I keep getting this error. Am I missing something? Is there someone who can run this code without getting the error?

BTW: Other opencv code (taking pictures from webcam) runs without problems....

At the moment I save the image to a temp JPG file. Using the imencode function I want to create the jpg file in the memory.

Thanks in advance and with best regards.