OpenCV Python保存jpg指定质量;给出SystemError [英] OpenCV Python save jpg specifying quality; gives SystemError
问题描述
我刚刚在Windows 7(32位)/Python 2.7.3上安装了最新的OpenCV 2.4,但是我仍然遇到与使用Beta版本时相同的错误:
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
有什么想法吗?使用元组代替列表,或在序列中添加尾随0都无济于事-同样的错误.
Any ideas ? Using tuple instead of list, or adding a trailing 0 to the sequence does not help - same error.
谢谢 -塞巴斯蒂安·哈斯(Sebastian Haase)
Thanks - Sebastian Haase
推荐答案
这可能是由于imwrite()
参数从Python到C,cv2.IMWRITE_JPEG_QUALITY
(类型为"long")的错误包装所致,以及引起一些奇怪的问题.您应该尝试将此常量转换为"int"类型:
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])
对我来说,它解决了这个问题(python 2.7.2,opencv 2.4.1)
for me it solved the problem (python 2.7.2, opencv 2.4.1)
这篇关于OpenCV Python保存jpg指定质量;给出SystemError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!