简体   繁体   中英

TypeError: imwrite() takes 2 positional arguments but 3 were given

I am trying to save jpg image with quality 80 by opencv. Here is the python script I tried:

cv2.imwrite(isdocker.DOCKER_PREFIX + IM.path + IM.name, IM.data, [(int(cv2.IMWRITE_JPEG_QUALITY),80)])

It pops up with an error 'TypeError: imwrite() takes 2 positional arguments but 3 were given'. I know a similar post in here . But I think its different issue. I have read the documentation from opencv and it seems they have changed something. Please help me.

Additional Information: Python 3.9.7 (default, May 19 2022, 00:53:30) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> cv2. version '4.5.5'

You almost have it. The third parameter is the codec's compression parameters , and it is given as a list of integers (not a list of tuples). Like this:

cv2.imwrite(imagePath, inputImage, [cv2.IMWRITE_JPEG_QUALITY, 80])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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