简体   繁体   English

OpenCV Python保存jpg指定质量; 给出了SystemError

[英]OpenCV Python save jpg specifying quality; gives SystemError

I just installed the newest OpenCV 2.4 on windows 7 (32bit)/ Python 2.7.3, 我刚刚在Windows 7(32位)/ Python 2.7.3上安装了最新的OpenCV 2.4,
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. 使用元组而不是列表,或者在序列中添加尾部0没有帮助 - 同样的错误。

Thanks - Sebastian Haase 谢谢 - 塞巴斯蒂安哈斯

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. 这可能是由于从Python到C, cv2.IMWRITE_JPEG_QUALITY (类型为“long”)的imwrite()参数的一些错误包装,并导致一些奇怪的问题。 You should try to convert this constant to "int" type: 您应该尝试将此常量转换为“int”类型:

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) 对我来说它解决了这个问题(python 2.7.2,opencv 2.4.1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM