Ask Your Question

OpenCV Python save jpg specifying quality; gives SystemError

asked 2012-07-04 14:37:12 -0500

sebhaase gravatar image
>>> import cv2
>>> a = cv2.imread(r"DMap.jpg")
>>> a.shape
(1080, 1920, 3)
>>> cv2.imwrite('img_CV2_90.jpg', a, [cv2.IMWRITE_JPEG_QUALITY, 90])
Traceback (most recent call last):
  File "<input>", line 1, in <module>
SystemError: error return without exception set

I just installed the newest OpenCV 2.4 on windows 7 (32bit)/ Python 2.7.3, but I still get the same error I got using the beta version.

Also get this error with 2.4.1. Any ideas ? Using tuple instead of list, or adding a trailing 0 to the sequence does not help - same error.

Thanks - Sebastian Haase

PS: I asked this on - not resolving the issue.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-07-04 16:26:46 -0500

Pavel Campr gravatar image

probably due to some wrong wrapping of imwrite() parameters from Python to C, cv2.IMWRITE_JPEG_QUALITY (which is of type "long") causes some weird problems... try to convert this constant to "int" type:

cv2.imwrite('img_CV2_90.jpg', a, [int(cv2.IMWRITE_JPEG_QUALITY), 90])

for me it solved the problem (python 2.7.2, opencv 2.4.1)

(answered on too)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-07-04 14:37:12 -0500

Seen: 6,820 times

Last updated: Jul 04 '12