34

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

sebhaase
  • 564
  • 1
  • 6
  • 10
  • did you remove all traces of the old package before installing the new one ? – oz123 May 02 '12 at 09:26
  • yes. As far as I can tell, I have only PYTHONPATH and PATH set into the c:/OpenCV2.4 directory. --- set PATH=%PATH%;C:\opencv2.4\build\x86\mingw\bin --- maybe that's the problem .... should I point to vc9 or vc10 instead of mingw ??? – sebhaase May 02 '12 at 14:24
  • when you do import cv2, and the then cv2.__file__ do you really see it is the new version ? – oz123 May 02 '12 at 14:34
  • >>> cv2.__file__ ==> 'C:\opencv2.4\build\python\2.7\cv2.pyd' – sebhaase May 03 '12 at 07:01
  • And I just also tried changing the PATH variable to point to C:\opencv2.4\build\x86\vc8\bin --- and then to ...vc9... --- both no change.. – sebhaase May 03 '12 at 07:03
  • Whoops --- just noticed that ..vc8.. doesn't even exists !! Tried vc10 -- no change .... why did it work when I used vc8 ?? And which SHOULD I use with python.org Python 2.7 ? – sebhaase May 03 '12 at 07:07

1 Answers1

61

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)

Community
  • 1
  • 1
pcampr
  • 766
  • 7
  • 4
  • this should be filed as a bug – sebhaase Jul 19 '12 at 07:17
  • Can we convert the quality without writing the image? I want to calculate `cv2.absdiff` between the original image and the converted image on a dataset with 500 000 images. so if I skip the io part, it would be more efficient. – Masoud Masoumi Moghadam Apr 28 '21 at 08:38
  • 1
    @MasoudMasoumiMoghadam maybe try `cv2.imencode()` instead, I'd guess it has the same params as `imwrite`, you can use `imdecode` after and avoid using the disk and save some io. – pcampr May 02 '21 at 19:35