Python错误:imwrite()最多需要3个参数(给定4个)

时间:2018-02-05 18:41:22

标签: python opencv interpolation cv2

我面临代码问题

import cv2
from pathlib import Path
from lib.cli import DirectoryProcessor
from plugins.PluginLoader import PluginLoader

class ExtractTrainingData(DirectoryProcessor):
    def create_parser(self, subparser, command, description):
        self.parser = subparser.add_parser(
            command,
            help="Extract the faces from a pictures.",
            description=description,
            epilog="Questions and feedback: \
            https://github.com/deepfakes/faceswap-playground"
        )

    def process(self):
        extractor_name = "Align" # TODO Pass as argument
        extractor = PluginLoader.get_extractor(extractor_name)()

        try:
            for filename in self.read_directory():
                image = cv2.imread(filename)
                for idx, face in self.get_faces(image):
                    resized_image = extractor.extract(image, face, 256)
                    output_file = self.output_dir / Path(filename).stem
                    cv2.imwrite(str(output_file) + str(idx) + Path(filename).suffix, resized_image, [int(cv2.IMWRITE_JPEG_QUALITY), 100], interpolation=cv2.INTER_NEAREST)


        except Exception as e:
            print('Failed to extract from image: {}. Reason: {}'.format(filename, e))

我想在函数 cv2.imwrite 中添加参数 interpolation = cv2.INTER_NEAREST ,但在输出中我无法从图像中提取:/ home / Jane /Desktop/50.jpg。原因: imwrite()最多需要3个参数(4个给定) 任何提示如何解决?我试过通过int

添加插值
cv2.imwrite(str(output_file) + str(idx) + Path(filename).suffix, resized_image, [int(cv2.IMWRITE_JPEG_QUALITY), 100], [int(interpolation), CV_INTER_LINEAR])

但这对我没有帮助。 :(

0 个答案:

没有答案