下記のサイトで紹介されている方法を使い、画像の区切られた領域内だけを塗りつぶしたいのですが、
リンク内容
ここでは画像の読み取りをpillowを使用して行っていますが、これをcv2.imreadで読み取った画像(numpy.ndarray)で行いたいのです。
実際にcv2.imreadに変更したところ、img1 = img.convert("RGB") でエラーが出たため、そこを消去してみると、
# Importing the pillow library's # desired modules from PIL import Image, ImageDraw import cv2 # Opening the image (R prefixed to # string in order to deal with '\' # in paths) img = cv2.imread("sample.png") # Coordinates of the pixel whose value # would be used as seed seed = (263, 70) # Pixel Value which would be used for # replacement rep_value = (255, 255, 0) # Calling the floodfill() function and # passing it image, seed, value and # thresh as arguments ImageDraw.floodfill(img, seed, rep_value, thresh=50) # Displaying the image img.show()
下記のようなエラーが出ます。
AttributeError: 'NoneType' object has no attribute 'load'
これは何が悪くてこうなっているのでしょうか。
また、ImageDraw.floodfillじゃなくてそういやopenCVにもfloodfillあるぞと思い、
newVal = (255, 255, 0) # Calling the floodfill() function and # passing it image, seed, value and # thresh as arguments cv2.floodFill(img, seed, newVal, thresh=50)
と変更してみたのですが
floodFill() missing required argument 'newVal' (pos 4)
とエラーが出ます。
どうすればよいでしょうか。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/09/10 02:36