以下の内容はhttps://anton0825.hatenablog.com/entry/2017/11/30/000000より取得しました。


draw.rectangleで矩形を描画しようとすると「TypeError: function takes exactly 1 argument (3 given)」エラー

以下のようなコードでbounding boxを描画しようとするとエラーになった。

img = Image.open(img_path)
draw = ImageDraw.Draw(img)
draw.rectangle((bbox[0][0], bbox[0][1], bbox[2][0], bbox[2][1]), outline=(255, 0, 0), width=2)

原因はImage.openで読み込んだjpeg画像の中にgrayscale のものが混ざっていたため。

その場合、ImageのmodeがL(grayscale)になり、RGBでbounding boxの色を指定するとエラーになる。

以下のコードでRGBに変換すると直った。

        if img.mode != "RGB":
            img = img.convert("RGB")

参考:

stackoverrun.com




以上の内容はhttps://anton0825.hatenablog.com/entry/2017/11/30/000000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14