OpenCV Python save jpg specifying quality; gives SystemError

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:

>>> 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 

Any ideas ? Using tuple instead of list, or adding a trailing 0 to the sequence does not help – same error.

Thanks – Sebastian Haase

Add Comment
1 Answer(s)

It is probably due to some wrong wrapping of the imwrite() parameters from Python to C, cv2.IMWRITE_JPEG_QUALITY (which is of type “long”), and causes some weird problems. You should 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 July 16, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.